home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / graphics / n-z / playkiss / src / k.e < prev    next >
Text File  |  1995-12-21  |  58KB  |  1,986 lines

  1.  
  2. /* Play KiSS v 0.88 */
  3.  
  4. /*
  5.     No copyright is claimed for *any* material within.
  6.   This source is *currently* Public Domain, and therefore open to free exploitation. */
  7.  
  8. /* Use at your own risk, and watch for hairy palms. */
  9.  
  10.  
  11. /*  November 9, 1994
  12.                                              Chad Randall 
  13.                                                         - mbissaymssiK Software, broken spork division
  14.                         Internet:  crandall@garnet.msen.com
  15.                             USNail:  229 S.Washington St.
  16.                                              Manchester, Michigan, 48158-9680 USA */
  17.  
  18. /* This sucker's not been tested but on my machine.  So let me know about any probs, 'kay? */
  19.  
  20. OPT LARGE
  21.  
  22. MODULE    'graphics/rastport','graphics/gfx','graphics/text','graphics/scale','graphics/view',
  23.                 'graphics/gfxbase','graphics/clip','graphics/layers','graphics/displayinfo'
  24. MODULE    'layers'
  25. MODULE    'intuition/intuition','intuition/screens','intuition/gadgetclass','intuition/screens',
  26.                 'intuition/pointerclass'
  27. MODULE    'libraries/gadtools','gadtools'
  28. MODULE    'dos/dos'
  29. MODULE    'libraries/asl','asl'
  30. MODULE    'tools/async'
  31. MODULE    'wb','workbench/workbench','workbench/startup'
  32. MODULE    'icon'
  33. MODULE    'exec/memory'
  34. MODULE    'utility/tagitem'
  35.  
  36. CONST    GS1_SIZE_X=640,GS2_SIZE_X=640,GS3_SIZE_X=640,GS4_SIZE_X=768
  37. CONST    GS1_SIZE_Y=400,GS2_SIZE_Y=400,GS3_SIZE_Y=480,GS4_SIZE_Y=512
  38. CONST    GS1_MAX_COLOR=16,GS2_MAX_COLOR=256,GS3_MAX_COLOR=256,GS4_MAX_COLOR=256
  39. CONST    GS1_MAX_CELL=128,GS2_MAX_CELL=192,GS3_MAX_CELL=256,GS4_MAX_CELL=256
  40. CONST SIZE_X_218=448,SIZE_Y_218=320,SIZE_X_224C=640,SIZE_Y_224C=400
  41. CONST FILE_MARK_CELL=$20,FILE_MARK_PALET=$10
  42. CONST DEFAULT_SIKII_DITHER=36
  43. CONST DEFAULT_SIKII_GOSA=1300
  44. CONST DEFAULT_COEF_GOSA=25
  45. CONST MAX_CELL=GS4_MAX_CELL
  46. CONST MAX_SET=10,MAX_PAL=10,MAX_COLOR=GS4_MAX_COLOR
  47. CONST MAX_SIZE_X=GS4_SIZE_X,MAX_SIZE_Y=GS4_SIZE_Y
  48. CONST DEFAULT_SIZE_X=SIZE_X_218,DEFAULT_SIZE_Y=SIZE_Y_218
  49. CONST FILENAME_LENGTH=64
  50.  
  51. ENUM OLD_,NEW_
  52. ENUM    DRAG_TOP,DRAG_PAUSE,DRAG_DIRTY,DRAG_BUFFER,DRAG_SMART
  53. CONST    CACHE_CHIP=0,CACHE_FAST=1,CACHE_NONEED=5,CACHE_NEED=6,CACHE_CHECK=7
  54.  
  55. OBJECT gcmap
  56.     red[256]:ARRAY OF CHAR
  57.     grn[256]:ARRAY OF CHAR
  58.     blu[256]:ARRAY OF CHAR
  59. ENDOBJECT
  60.  
  61. OBJECT cello
  62.     xsize,ysize:INT
  63.     xoffset,yoffset:INT
  64.     mark:INT
  65.     fix:INT
  66.     cache:INT
  67.     palet_num:CHAR
  68.     bit_per_pixel:CHAR
  69.     catch:LONG
  70.     set[MAX_SET]:ARRAY OF CHAR
  71.     x[MAX_SET]:ARRAY OF INT
  72.     y[MAX_SET]:ARRAY OF INT
  73.     pix:PTR TO bitmap
  74.     pix_rp:PTR TO rastport
  75.     clip_pix:PTR TO bitmap
  76.     clip_pix_rp:PTR TO rastport
  77.     name:LONG
  78.     catchsize:LONG
  79. ENDOBJECT
  80.  
  81. OBJECT paleto
  82.     name[FILENAME_LENGTH]:ARRAY OF CHAR
  83.     format:CHAR
  84.     color_num:CHAR
  85.     palet_num:CHAR
  86.     bit_per_pixel:CHAR
  87.     pb[MAX_PAL]:ARRAY OF INT
  88.     color[18]:ARRAY OF LONG
  89. ENDOBJECT
  90.  
  91. OBJECT color
  92.     red:LONG
  93.     green:LONG
  94.     blue:LONG
  95. ENDOBJECT
  96.  
  97. ENUM SCAN_NORMAL, SCAN_EOL, SCAN_SETDATA, SCAN_IBM, SCAN_CEL, SCAN_CELNUM, SCAN_CELNAME, SCAN_CELNEXT
  98.  
  99. DEF filename[500]:STRING
  100.  
  101. DEF vp:PTR TO viewport,cm,depth,scrw,scrh,menu,vis
  102. DEF rp:PTR TO rastport,winw,winh
  103.  
  104. DEF quit=FALSE,newproj=FALSE
  105. DEF mode=0
  106. DEF config_size_x,config_size_y
  107. DEF cell[MAX_CELL]:ARRAY OF cello
  108. DEF palet[20]:ARRAY OF paleto
  109.  
  110. DEF barh=8
  111. DEF pb[MAX_SET]:LIST
  112. DEF current_palet=0
  113. DEF current_set=0
  114. DEF disp:PTR TO rastport
  115. DEF scr:PTR TO screen
  116. DEF win:PTR TO window,outwin:PTR TO window
  117. DEF fixxed=FALSE,fixpow=0,fixpower=0,rtdrag=DRAG_TOP,waittof=TRUE,hand=FALSE,bound=TRUE
  118. DEF string[500]:STRING
  119. DEF iconbmap=0:PTR TO bitmap,iconwidth,iconheight,oldx,oldy
  120. DEF copybmap=0:PTR TO bitmap,copyrast:PTR TO rastport
  121. DEF backbmap=0:PTR TO bitmap,backrast:PTR TO rastport
  122. DEF maskbmap=0:PTR TO bitmap
  123. DEF blankbmap=0:PTR TO bitmap,maximumw=1,maximumh=1
  124. DEF hand1=0,hand2=0,hand3=0
  125. DEF curobj=0,offx,offy,dragmode=0,origx,origy
  126. DEF filereq=0:PTR TO filerequester
  127. DEF modeid=0,sh=400,sw=640
  128. ENUM OFF=FALSE,ON=TRUE
  129. DEF outputmode=0
  130. DEF pauseflag=FALSE
  131. RAISE "CHIP" IF AllocBitMap()=FALSE
  132. RAISE "MEM" IF AllocMem()=FALSE
  133. RAISE "MEM" IF New()=FALSE
  134. RAISE "^C" IF CtrlC()=TRUE
  135.  
  136. PROC check_str(str)
  137.     DEF p
  138.     p:=str;WHILE (Char(p)<>0)
  139.         IF ((Char(p)=10) OR (Char(p)=13) OR (Char(p)=9)) THEN PutChar(p," ")
  140.         IF (Char(p)=";")
  141.             PutChar(p,0)
  142.         ENDIF
  143.         EXIT (Char(p)=";")
  144.     p:=p+1;ENDWHILE
  145. ENDPROC
  146.  
  147. versionstring:
  148. CHAR    '\0$VER: playkiss 0.88 (21.11.94) \tPUBLIC DOMAIN --- NOT FOR RESALE\0\0'
  149.  
  150. /*PROC skip_str(str) ->char *skip_str(char *str)
  151.     DEF p                                                                                        ->       char *p;
  152.     p:=str;WHILE (Char(p)=" ");p:=p+1;ENDWHILE             ->        for (p=str;*p==' ';p++);
  153.   WHILE (Char(p)<>" ")                                                        ->        for (;*p!=' ';p++)
  154.         IF (Char(p)=0) THEN RETURN p                                    ->    if (*p=='\0') return(p);
  155.     p:=p+1;ENDWHILE
  156.     WHILE (Char(p)=" ");p:=p+1;ENDWHILE                            ->    for (;*p==' ';p++);
  157.   RETURN p
  158. ENDPROC*/
  159.  
  160. PROC check_kiss_header(fp)
  161.     DEF buf
  162.     buf:=[0,0,0,0]:LONG
  163.     Read(fp,buf,4)
  164.     Seek(fp,0,OFFSET_BEGINNING)
  165.     IF Long(buf)="KiSS" THEN RETURN 1
  166. ENDPROC FALSE
  167.  
  168.  
  169. PROC load_data_cell(fn,num) HANDLE
  170.     DEF fh=0
  171.     DEF buf[64]:ARRAY OF CHAR,tmp_buf
  172.     DEF i,t,j,x,y,flag
  173.     DEF b[MAX_SIZE_X]:ARRAY OF CHAR
  174.     DEF dir[500]:STRING,oldfile[100]:STRING
  175.     DEF nx,p,nrp
  176.  
  177.     DEF temprp=0:PTR TO rastport
  178.     DEF array=0
  179.     DEF tempbitmap=0:PTR TO bitmap
  180.  
  181.     splitname(filename,dir,oldfile)
  182.     AddPart(dir,fn,490)
  183.     fh:=as_Open(dir,MODE_OLDFILE,6,4000)
  184.     IF fh
  185.         as_Read(fh,buf,4)
  186.         IF Long(buf)="KiSS"
  187.             as_Read(fh,buf,28)
  188.             IF Char(buf)<>FILE_MARK_CELL THEN Raise("|cel")
  189.             cell[num].xsize:=((Char(buf+ 5)*256)+Char(buf+ 4))
  190.             cell[num].ysize:=(Char(buf+7)*256)+Char(buf+6)
  191.             cell[num].xoffset:=Char(buf+9)*256+Char(buf+8)
  192.             cell[num].yoffset:=Char(buf+11)*256+Char(buf+10)
  193.             cell[num].bit_per_pixel:=smaller(bigger(Char(buf+1),4),8)
  194.         ELSE
  195.             cell[num].xsize:=(Char(buf+1)*256+Char(buf))
  196.             cell[num].ysize:=Char(buf+3)*256+Char(buf+2)
  197.             cell[num].xoffset:=0
  198.             cell[num].yoffset:=0
  199.             cell[num].bit_per_pixel:=4
  200.         ENDIF
  201.  
  202.         IF cell[num].bit_per_pixel=8
  203.             cell[num].pix:=AllocBitMap(cell[num].xsize,cell[num].ysize,8, BMF_INTERLEAVED OR BMF_CLEAR, NIL)
  204.             cell[num].pix_rp:=New(SIZEOF rastport)
  205.             InitRastPort(cell[num].pix_rp)
  206.             cell[num].pix_rp.bitmap:=cell[num].pix
  207.  
  208.             cell[num].clip_pix:=AllocBitMap(cell[num].xsize,cell[num].ysize,1, BMF_INTERLEAVED OR BMF_CLEAR, NIL)
  209.             cell[num].clip_pix_rp:=New(SIZEOF rastport)
  210.             InitRastPort(cell[num].clip_pix_rp)
  211.             cell[num].clip_pix_rp.bitmap:=cell[num].clip_pix
  212.         ELSE
  213.             cell[num].pix:=AllocBitMap(cell[num].xsize,cell[num].ysize,4, BMF_INTERLEAVED OR BMF_CLEAR, NIL)
  214.             cell[num].pix_rp:=New(SIZEOF rastport)
  215.             InitRastPort(cell[num].pix_rp)
  216.             cell[num].pix_rp.bitmap:=cell[num].pix
  217.  
  218.             cell[num].clip_pix:=AllocBitMap(cell[num].xsize,cell[num].ysize,1, BMF_INTERLEAVED OR BMF_CLEAR, NIL)
  219.             cell[num].clip_pix_rp:=New(SIZEOF rastport)
  220.             InitRastPort(cell[num].clip_pix_rp)
  221.             cell[num].clip_pix_rp.bitmap:=cell[num].clip_pix
  222.         ENDIF
  223.  
  224.         temprp:=New(SIZEOF rastport)
  225.         InitRastPort(temprp)
  226.         CopyMem(cell[num].pix_rp,temprp,SIZEOF rastport)
  227.         tempbitmap:=AllocBitMap(cell[num].xsize,1,8, BMF_CLEAR,NIL)
  228.         temprp.bitmap:=tempbitmap
  229.         array:=New(cell[num].xsize+100)
  230.  
  231.  
  232. -> NEED TO OPTIMIZE THE FOLLOWING:::
  233.  
  234.         IF cell[num].bit_per_pixel=8
  235.             nx:=cell[num].xsize
  236.             nrp:=cell[num].pix_rp
  237.             FOR i:=0 TO cell[num].ysize-1
  238.  
  239.                 as_Read(fh,b,nx)
  240.  
  241.                 FOR t:=0 TO nx-1
  242.                     IF (p:=Char(b+t))
  243.                         SetAPen(nrp,Char(b+t))
  244.                         WritePixel(nrp,t,i)
  245.                     ENDIF
  246.                 ENDFOR
  247.             ENDFOR
  248.         ENDIF
  249.  
  250.         IF cell[num].bit_per_pixel=4
  251.             nx:=cell[num].xsize
  252.             nrp:=cell[num].pix_rp
  253.             FOR i:=0 TO cell[num].ysize-1
  254.  
  255.                 as_Read(fh,b,nx/2)
  256.  
  257.                 FOR t:=0 TO (nx-1) STEP 2
  258. /*                IF (p:= (Shr(Char(b+(t/2)),4) AND $0F))
  259.                     SetAPen(nrp,p)
  260.                     WritePixel(nrp,t,i)
  261.                 ENDIF
  262.                 IF (p:= (Char(b+(t/2)) AND $0F))
  263.                     SetAPen(nrp,p)
  264.                     WritePixel(nrp,t+1,i)
  265.                 ENDIF*/
  266.  
  267.                     PutChar(array+(t),(Shr(Char(b+(t/2)),4) AND $0F))
  268.                     PutChar(array+(t)+1,((Char(b+(t/2))) AND $0F))
  269.                 ENDFOR
  270.                 IF (nrp<>0) THEN WritePixelLine8(nrp,0,i,nx,array,temprp)
  271.             ENDFOR
  272.         ENDIF
  273.  
  274.         maximumw:=bigger(maximumw,nx)
  275.         maximumh:=bigger(maximumh,cell[num].ysize)
  276.  
  277.         IF ((cell[num].pix<>0) AND (cell[num].clip_pix<>0))
  278.             planesclip(cell[num].pix,cell[num].clip_pix,cell[num].xsize,cell[num].ysize)
  279.             FOR i:=1 TO 7;PutLong(cell[num].clip_pix+8+(i*4),Long(cell[num].clip_pix+8));ENDFOR
  280.             PutChar(cell[num].clip_pix+5,8)
  281.         ENDIF
  282.     ENDIF
  283. EXCEPT DO
  284.     IF fh;as_Close(fh);ELSE
  285.         IF outwin
  286.             StringF(string,'Object not found:"\s" ',fn)
  287.             SetWindowTitles(outwin,string,-1)
  288.             DisplayBeep(0)
  289.             Delay(30)
  290.         ENDIF
  291.     ENDIF
  292.     
  293.     IF temprp THEN Dispose(temprp)
  294.     IF array THEN Dispose(array)
  295.     IF tempbitmap THEN FreeBitMap(tempbitmap)
  296.     IF exception="CHIP"
  297.         WriteF('Not enough CHIP memory.\n')
  298.         DisplayBeep(0)
  299.     ENDIF
  300.     IF exception="^C" THEN ReThrow()
  301. ENDPROC
  302.  
  303. PROC cache_cell(num,mode)  -> bitmap must be INTERLEAVED!!!  ie, *ONE* raster!!!!
  304.     DEF newmode=CACHE_NONEED,plane:PTR TO bitmap
  305.     IF (mode=CACHE_CHECK)
  306.         IF (cell[num].set[current_set]<10)
  307.             newmode:=CACHE_NEED
  308.         ENDIF
  309.     ENDIF
  310.     IF mode=CACHE_NEED THEN newmode:=CACHE_NEED
  311.     IF (newmode=CACHE_NONEED)
  312.         IF (cell[num].cache=CACHE_CHIP)
  313.             IF cell[num].pix=0 THEN RETURN
  314.             cell[num].catchsize:=(cell[num].pix.bytesperrow*cell[num].pix.rows)
  315.             cell[num].catch:=AllocMem(cell[num].catchsize,MEMF_ANY)
  316.             CopyMem(Long(cell[num].pix+8),cell[num].catch,cell[num].catchsize)
  317.             FreeBitMap(cell[num].pix);cell[num].pix:=0
  318.             cell[num].cache:=CACHE_FAST
  319.         ENDIF
  320.     ENDIF
  321.     IF (newmode=CACHE_NEED)
  322.         IF (cell[num].cache=CACHE_FAST)
  323.             IF cell[num].bit_per_pixel=8
  324.                 cell[num].pix:=AllocBitMap(cell[num].xsize,cell[num].ysize,8, BMF_INTERLEAVED OR BMF_CLEAR, NIL)
  325.             ELSE
  326.                 cell[num].pix:=AllocBitMap(cell[num].xsize,cell[num].ysize,4, BMF_INTERLEAVED OR BMF_CLEAR, NIL)
  327.             ENDIF
  328.             cell[num].pix_rp.bitmap:=cell[num].pix
  329.             IF (cell[num].catch<>0)
  330.                 IF (cell[num].pix<>0)
  331.                     CopyMem(cell[num].catch,Long(cell[num].pix+8),cell[num].catchsize)
  332.                     FreeMem(cell[num].catch,cell[num].catchsize);cell[num].catch:=0
  333.                 ELSE
  334.                     WriteF('nopix?!!!? \n');DisplayBeep(0)
  335.                 ENDIF
  336.             ELSE
  337.                 WriteF('nomem???!? \n');DisplayBeep(0)
  338.             ENDIF
  339.             cell[num].cache:=CACHE_CHIP
  340.         ENDIF
  341.     ENDIF            
  342. ENDPROC
  343.  
  344. PROC disposesaveback()
  345.     DEF i
  346.     IF iconbmap THEN FreeBitMap(iconbmap)
  347.     IF copybmap THEN FreeBitMap(copybmap)
  348.     IF backbmap THEN FreeBitMap(backbmap)
  349.     IF backrast THEN Dispose(backrast)
  350.     IF copyrast THEN Dispose(copyrast)
  351.     IF maskbmap
  352.         PutChar(maskbmap+5,1)
  353.         FOR i:=1 TO 7;PutLong(maskbmap+8+(i*4),0);ENDFOR
  354.         FreeBitMap(maskbmap)
  355.     ENDIF
  356.     iconbmap:=0;backbmap:=0;maskbmap:=0;copybmap:=0;backrast:=0;copyrast:=0
  357. ENDPROC
  358.  
  359. PROC createsaveback(obj)
  360.     DEF i,minw=16,minh=8,dummy,mask
  361.     disposesaveback()
  362.     FOR i:=0 TO MAX_CELL-1
  363.         IF cell[i].mark=obj
  364.             minw:=bigger(minw,cell[i].xoffset+cell[i].xsize+1)
  365.             minh:=bigger(minh,cell[i].yoffset+cell[i].ysize+1)
  366.         ENDIF
  367.     ENDFOR
  368.     iconwidth:=minw
  369.     iconheight:=minh
  370.     iconbmap:=AllocBitMap(minw,minh,retdepth(mode), BMF_CLEAR OR IF (rtdrag<DRAG_DIRTY) THEN BMF_INTERLEAVED ELSE 0,NIL)
  371.     IF ((rtdrag=DRAG_BUFFER) OR (rtdrag=DRAG_SMART))
  372.         IF (((rtdrag=DRAG_SMART) AND (minw<160) AND (minh<280)) OR (rtdrag=DRAG_BUFFER))
  373.             copybmap:=AllocBitMap(minw,minh,retdepth(mode), BMF_INTERLEAVED,NIL)
  374.             copyrast:=New(SIZEOF rastport)
  375.             InitRastPort(copyrast)
  376.             copyrast.bitmap:=copybmap
  377.         ENDIF
  378.     ENDIF
  379.     backbmap:=AllocBitMap(minw,minh,retdepth(mode), BMF_INTERLEAVED,NIL)
  380.     backrast:=New(SIZEOF rastport)
  381.     InitRastPort(backrast)
  382.     backrast.bitmap:=backbmap
  383.     maskbmap:=AllocBitMap(minw,minh,1,IF (rtdrag=FALSE) THEN  BMF_INTERLEAVED ELSE 0,NIL)
  384.  
  385.     FOR i:=MAX_CELL-1 TO 0 STEP -1
  386.         IF (cell[i].mark=obj)
  387.             IF (cell[i].set[current_set]<10)
  388.                 IF ((cell[i].clip_pix<>0) AND (iconbmap<>0)) THEN BltBitMap(cell[i].clip_pix,0,0,iconbmap,cell[i].xoffset,cell[i].yoffset,cell[i].xsize,cell[i].ysize,$20,$FFFFFFFF,0)
  389.                 IF ((cell[i].pix<>0) AND (iconbmap<>0)) THEN BltBitMap(cell[i].pix,0,0,iconbmap,cell[i].xoffset,cell[i].yoffset,cell[i].xsize,cell[i].ysize,$E0,$FFFFFFFF,0)
  390.                 dummy:=cell[i].palet_num
  391.                 SELECT dummy
  392.                     CASE 0 ;mask:=%00000000
  393.                     CASE 1 ;mask:=%00010000
  394.                     CASE 2 ;mask:=%00100000
  395.                     CASE 3 ;mask:=%00110000
  396.                     CASE 4 ;mask:=%01000000
  397.                     CASE 5 ;mask:=%01010000
  398.                     CASE 6 ;mask:=%01100000
  399.                     CASE 7 ;mask:=%01110000
  400.                     CASE 8 ;mask:=%10000000
  401.                     CASE 9 ;mask:=%10010000
  402.                     CASE 10;mask:=%10100000
  403.                     CASE 11;mask:=%10110000
  404.                     CASE 12;mask:=%11000000
  405.                     CASE 13;mask:=%11010000
  406.                     CASE 14;mask:=%11100000
  407.                     CASE 15;mask:=%11110000
  408.                 ENDSELECT
  409.                 dummy:=retdepth(mode)
  410.                 SELECT dummy
  411.                     CASE 4;mask:=(mask AND %00000000)
  412.                     CASE 5;mask:=(mask AND %00010000)
  413.                     CASE 6;mask:=(mask AND %00110000)
  414.                     CASE 7;mask:=(mask AND %01110000)
  415.                     CASE 8;mask:=(mask AND %11110000)
  416.                 ENDSELECT
  417.                 IF ((cell[i].clip_pix<>0) AND (iconbmap<>0)) THEN BltBitMap(cell[i].clip_pix,0,0,iconbmap,cell[i].xoffset,cell[i].yoffset,cell[i].xsize,cell[i].ysize,$E0,mask,0)
  418.             ENDIF
  419.         ENDIF            
  420.     ENDFOR
  421.  
  422.     planesclip(iconbmap,maskbmap,iconwidth,iconheight)
  423.     PutChar(maskbmap+5,8)
  424.     FOR i:=1 TO 7;PutLong(maskbmap+8+(i*4),Long(maskbmap+8));ENDFOR
  425.  
  426. ENDPROC
  427.  
  428. PROC reportmousemoves(win:PTR TO window)
  429.     Forbid()
  430.     win.flags:=win.flags OR WFLG_REPORTMOUSE
  431.     Permit()
  432. ENDPROC
  433. PROC noreportmousemoves(win:PTR TO window);DEF flag
  434.     Forbid()
  435.     flag:=win.flags
  436.     IF (flag AND WFLG_REPORTMOUSE) THEN flag:=flag-WFLG_REPORTMOUSE
  437.     win.flags:=flag
  438.     Permit()
  439. ENDPROC
  440.  
  441.  
  442. PROC main() HANDLE
  443.     DEF i,ii,t,zz,tt,zzz
  444.     DEF mes:PTR TO intuimessage
  445.     DEF hit,hitflag=0,iadd:PTR TO menuitem,drawx,drawy
  446.     DEF dir[500]:STRING,file[250]:STRING,buffer
  447.     DEF args:PTR TO wbarg,wstr[250]:STRING,toolobject=NIL:PTR TO diskobject
  448.     DEF region1,rectangle:PTR TO rectangle
  449.     DEF olddir,dirrr,wb:PTR TO wbstartup
  450.     DEF argarray[32]:LIST,rdarg=0,gotme=0,check,code=0,du=0
  451.     DEF zx,zy,zw,zh,zox,zoy
  452.     DEF oldfh=0,newfh=0,filebuf=0,bufptr,filelen=1
  453.     DEF menuverify=FALSE
  454.  
  455.     IF (KickVersion(39)=0)
  456.         Raise("Kick")
  457.     ENDIF
  458.  
  459.     buffer:=New(260*12)
  460.     IF (iconbase:=OpenLibrary('icon.library', 37))=NIL THEN Raise("LIB")
  461.     IF (aslbase:=OpenLibrary('asl.library', 37))=NIL THEN Raise("LIB")
  462.     IF (gadtoolsbase:=OpenLibrary('gadtools.library',37))=NIL THEN Raise("LIB")
  463.     IF (layersbase:=OpenLibrary('layers.library',37))=NIL THEN Raise("LIB")
  464.  
  465.     NEW cell[MAX_CELL]
  466.     NEW palet[16]
  467.     NEW rectangle
  468.  
  469.     IF wbmessage<>NIL
  470.         outputmode:=TRUE
  471.         wb:=wbmessage;args:=wb.arglist
  472.         olddir:=CurrentDir(args.lock)
  473.         IF args.name>0
  474.             GetCurrentDirName(wstr,250)
  475.             StrCopy(filename,wstr,ALL);AddPart(filename,'',490)
  476.             StrAdd(wstr,args.name,ALL)
  477.             IF (toolobject:=GetDiskObjectNew(wstr))
  478.                 IF (du:=FindToolType(toolobject.tooltypes,'DRAG_STRENGTH'))
  479.                     StrToLong(du,{fixpow})
  480.                     fixpow:=limit(fixpow,0,9)
  481.                 ENDIF
  482.                 IF (du:=FindToolType(toolobject.tooltypes,'FIXED'))
  483.                     IF MatchToolValue(du,'yes');fixxed:=FALSE;fixpow:=0;ELSE;fixxed:=TRUE;fixpow:=9;ENDIF
  484.                 ENDIF
  485.                 IF (du:=FindToolType(toolobject.tooltypes,'KISS_DIRECTORY'))
  486.                     StrCopy(filename,du,ALL)
  487.                     AddPart(filename,'',490)
  488.                 ENDIF
  489.                 IF (du:=FindToolType(toolobject.tooltypes,'HANDPOINTER'))
  490.                     IF MatchToolValue(du,'yes');hand:=TRUE;ELSE;hand:=FALSE;ENDIF
  491.                 ENDIF
  492.                 IF (du:=FindToolType(toolobject.tooltypes,'BLANKPOINTER'))
  493.                     IF MatchToolValue(du,'yes');hand:=3;ENDIF
  494.                 ENDIF
  495.                 IF (du:=FindToolType(toolobject.tooltypes,'BOUNDS'))
  496.                     IF MatchToolValue(du,'no');bound:=FALSE;ELSE;bound:=TRUE;ENDIF
  497.                 ENDIF
  498.                 IF (du:=FindToolType(toolobject.tooltypes,'DRAGTYPE'))
  499.                     StrToLong(du,{rtdrag})
  500.                     du:=limit(du,DRAG_TOP,DRAG_SMART)
  501.                 ENDIF
  502.                 IF (du:=FindToolType(toolobject.tooltypes,'MODEID'))
  503.                     IF Char(du)<>"$"
  504.                         StrToLong(du,{modeid})
  505.                     ELSE
  506.                         modeid:=hex2int(du)
  507.                     ENDIF
  508.                 ENDIF
  509.                 IF (du:=FindToolType(toolobject.tooltypes,'SCREEN_WIDTH'))
  510.                     StrToLong(du,{sw})
  511.                 ENDIF
  512.                 IF (du:=FindToolType(toolobject.tooltypes,'SCREEN_HEIGHT'))
  513.                     StrToLong(du,{sh})
  514.                 ENDIF
  515.                 IF (du:=FindToolType(toolobject.tooltypes,'WAITBLITTER'))
  516.                     IF MatchToolValue(du,'no');waittof:=FALSE;ELSE;waittof:=TRUE;ENDIF
  517.                 ENDIF
  518.                 FreeDiskObject(toolobject)
  519.             ENDIF
  520.         ENDIF
  521.         CurrentDir(olddir)
  522.  
  523. ->        StrCopy(filename,wstr,ALL)
  524.         IF wb.numargs>1
  525.             olddir:=args[].lock++ ->skip our lock! olddir is meaningless at this point
  526.             IF args.lock
  527.                 olddir:=CurrentDir(args.lock)
  528.                 GetCurrentDirName(filename,490)
  529.                 NameFromLock(args.lock,wstr,240)
  530.                 CurrentDir(olddir)
  531.                 AddPart(filename,args.name,490)
  532.                 gotme:=TRUE
  533.             ENDIF
  534.         ENDIF
  535.     ELSE
  536.         FOR i:=0 TO 30
  537.             argarray[i]:=NIL
  538.         ENDFOR
  539.         rdarg:=ReadArgs('FILE,M=MODEID/K,SW=SCREENWIDTH/N/K,SH=SCREENHEIGHT/N/K,D=DRAGMODE/N/K,DS=DRAGSTRENGTH/B/K,X=NOFIX/S,H=HAND/S,BP=BLANKPTRP/S,NWB=NOWAITBLIT/S,NOB=NOBOUNDS/S',argarray,0)
  540.         IF rdarg
  541.             IF argarray[0]
  542.                 StrCopy(filename,argarray[0],ALL)
  543.                 gotme:=TRUE
  544.             ENDIF
  545.             IF argarray[1]
  546.                 IF (Char(argarray[1])<>"$")
  547.                     StrToLong(argarray[1],{modeid})
  548.                 ELSE
  549.                     modeid:=hex2int(argarray[1])
  550.                 ENDIF
  551.             ENDIF
  552.             IF argarray[2]
  553.                 sw:=argarray[2]
  554.                 sw:=^sw
  555.             ENDIF
  556.             IF argarray[3]
  557.                 sh:=argarray[3]
  558.                 sh:=^sh
  559.             ENDIF
  560.             IF argarray[4]
  561.                 rtdrag:=argarray[4]
  562.                 rtdrag:=^rtdrag
  563.                 rtdrag:=limit(rtdrag,DRAG_TOP,DRAG_SMART)
  564.             ENDIF
  565.             IF argarray[5]
  566.                 fixpow:=argarray[5]
  567.                 fixpow:=^fixpow
  568.                 fixpow:=limit(fixpow,0,9)
  569.             ENDIF
  570.             IF argarray[6];fixxed:=TRUE;fixpow:=9;ENDIF
  571.             IF argarray[7] THEN hand:=TRUE
  572.             IF argarray[8] THEN hand:=3
  573.             IF argarray[9] THEN waittof:=FALSE
  574.             IF argarray[10] THEN bound:=FALSE
  575.             FreeArgs(rdarg)
  576.         ENDIF
  577.     ENDIF
  578.  
  579.     FOR i:=0 TO MAX_CELL-1
  580.         cell[i].name:=String(FILENAME_LENGTH)
  581.         cell[i].mark:=-66
  582.         cell[i].cache:=0
  583.         cell[i].pix:=0
  584.         cell[i].clip_pix:=0
  585.     ENDFOR
  586.     FOR i:=0 TO 15
  587.         FOR ii:=0 TO 15
  588.             palet[i].color[ii]:=0
  589.         ENDFOR
  590.     ENDFOR
  591.  
  592.     PutLong({hand1bm}+8,{hand1dataa})
  593.     PutLong({hand1bm}+12,{hand1datab})
  594.     PutLong({hand2bm}+8,{hand2dataa})
  595.     PutLong({hand2bm}+12,{hand2datab})
  596.     PutLong({hand3bm}+8,{hand3dataa})
  597.     PutLong({hand3bm}+12,{hand3datab})
  598.     hand1:=NewObjectA(NIL,'pointerclass',[POINTERA_BITMAP,{hand1bm},
  599.                             POINTERA_XOFFSET,-7,
  600.                             POINTERA_YOFFSET,0,
  601.                             POINTERA_XRESOLUTION,POINTERXRESN_SCREENRES,
  602.                             POINTERA_YRESOLUTION,POINTERYRESN_SCREENRESASPECT,
  603.                             NIL,NIL])
  604.     hand2:=NewObjectA(NIL,'pointerclass',[POINTERA_BITMAP,{hand2bm},
  605.                             POINTERA_XOFFSET,-7,
  606.                             POINTERA_YOFFSET,1,
  607.                             POINTERA_XRESOLUTION,POINTERXRESN_SCREENRES,
  608.                             POINTERA_YRESOLUTION,POINTERYRESN_SCREENRESASPECT,
  609.                             NIL,NIL])
  610.     hand3:=NewObjectA(NIL,'pointerclass',[POINTERA_BITMAP,{hand3bm},
  611.                             POINTERA_XRESOLUTION,POINTERXRESN_HIRES,
  612.                             POINTERA_YRESOLUTION,POINTERYRESN_HIGH,
  613.                             POINTERA_XOFFSET,0,
  614.                             POINTERA_YOFFSET,0,
  615.                             NIL,NIL])
  616.  
  617.  
  618.     filereq:=AllocAslRequest(ASL_FILEREQUEST,[ASLFR_INITIALPATTERN,'#?.CNF',NIL,NIL])
  619.  
  620.     region1:=NewRegion()
  621.  
  622.     WHILE quit=FALSE
  623.         IF (gotme<>TRUE)
  624.             splitname(filename,dir,file)
  625.             WbenchToFront()
  626.             ii:=AslRequest(filereq,[ASL_HAIL,'Select .CNF file',
  627.                                 ASL_OKTEXT,'_Open',ASL_FILE,file,ASL_DIR,dir,
  628.                                 ASLFR_DOPATTERNS,TRUE,ASLFR_DOSAVEMODE,FALSE,FILF_NEWIDCMP,TRUE,NIL,NIL])
  629.             IF ii
  630.                 StrCopy(filename,filereq.drawer,ALL)
  631.                 AddPart(filename,filereq.file,490)
  632.             ELSE
  633.                 quit:=TRUE;StrCopy(filename,'',ALL)
  634.             ENDIF
  635.         ENDIF    ;gotme:=FALSE
  636.         mode:=0
  637.         maximumw:=1;maximumh:=1
  638.         scr:=LockPubScreen('Workbench')
  639.         config_size_x:=scr.width
  640.         config_size_y:=(scr.height)
  641.         IF sw THEN config_size_x:=sw
  642.         IF sh THEN config_size_y:=sh
  643.         barh:=scr.barheight
  644.         UnlockPubScreen(0,scr);scr:=0
  645.         IF openproj(filename)
  646.             openscreen(retdepth(mode))
  647.             docheck(fixpow+100,TRUE)
  648.             SELECT fixpow
  649.             CASE 0;fixpower:=0
  650.             CASE 1;fixpower:=32
  651.             CASE 2;fixpower:=128
  652.             CASE 3;fixpower:=256
  653.             CASE 4;fixpower:=1024
  654.             CASE 5;fixpower:=2048
  655.             CASE 6;fixpower:=4096
  656.             CASE 7;fixpower:=8192
  657.             CASE 8;fixpower:=16384
  658.             CASE 9;fixpower:=32768
  659.             ENDSELECT
  660.             ->blankbmap:=AllocBitMap(maximumw,maximumh,1, BMF_CLEAR,NIL)
  661.             GetRGB32(cm,0,256,buffer)
  662.             current_set:=0
  663.             docheck(20+current_palet,FALSE)
  664.             current_palet:=pb[current_set]
  665.             docheck(20+current_palet,TRUE)
  666.             updatecolors()
  667.             updatelist()
  668.             newproj:=FALSE
  669.             WHILE ((quit=FALSE) AND (newproj=FALSE))
  670.                 IF ((hand<>0) AND (hand1<>0) AND (hand2<>0) AND (menuverify=FALSE))
  671.                     IF (retdepth(mode)<5)
  672.                         SetRGB32(vp,17,$FFFFFFFF,$DDDDDDDD,$88888888)
  673.                         SetRGB32(vp,18,$99999999,$66666666,$33333333)
  674.                         SetRGB32(vp,19,0,0,0)
  675.                     ENDIF
  676.                     IF (hand<>3)
  677.                         IF (dragmode=FALSE)
  678.                             SetWindowPointerA(win,[WA_POINTER,hand1,WA_POINTERDELAY,FALSE,NIL,NIL])
  679.                         ELSE
  680.                             SetWindowPointerA(win,[WA_POINTER,hand2,WA_POINTERDELAY,FALSE,NIL,NIL])
  681.                         ENDIF
  682.                     ELSE
  683.                         IF (dragmode<>FALSE)
  684.                             SetWindowPointerA(win,[WA_POINTER,hand3,WA_POINTERDELAY,FALSE,NIL,NIL])
  685.                         ELSE
  686.                             ClearPointer(win)
  687.                         ENDIF
  688.                     ENDIF                        
  689.                 ELSE
  690.                     ClearPointer(win)
  691.                 ENDIF
  692.                 Wait(-1)
  693.                 CtrlC()
  694.                 hitflag:=0
  695.                 WHILE (mes:=Gt_GetIMsg(win.userport))
  696.                     IF (mes.class=IDCMP_MENUVERIFY)
  697.                         IF dragmode
  698.                             mes.code:=MENUCANCEL
  699.                             IF (dragmode=TRUE)
  700.                                 IF backrast THEN ClipBlit(backrast,0,0,rp,oldx-offx,oldy-offy,iconwidth,iconheight,$C0)
  701.                                 placeobj(curobj,origx,origy);pauseflag:=TRUE
  702.                                 disposesaveback()
  703.                                 dragmode:=FALSE;curobj:=-1;noreportmousemoves(win)
  704.                                 SetWindowTitles(win,-1,' Play KiSS 0.88')
  705.                             ENDIF
  706.                         ELSE
  707.                             menucolors(buffer)
  708.                             ClearPointer(win);menuverify:=TRUE
  709.                         ENDIF
  710.                     ENDIF
  711.                     IF (mes.class=IDCMP_MENUPICK)
  712.                         ClearPointer(win);menuverify:=FALSE
  713.                         code:=mes.code
  714.                         WHILE (code<>MENUNULL)
  715.                             iadd:=ItemAddress(menu,code)
  716.                             IF iadd
  717.                                 hit:=Long(iadd+34)
  718.                                 check:=(Int(iadd+12) AND CHECKED)
  719. ->                                IF hit=75 THEN fixxed:=IF check THEN FALSE ELSE TRUE
  720.                                 IF ((hit>=100) AND (hit<=109))
  721.                                     SELECT hit
  722.                                     CASE 100;fixpower:=0;fixpow:=0
  723.                                     CASE 101;fixpower:=32;fixpow:=1
  724.                                     CASE 102;fixpower:=128;fixpow:=2
  725.                                     CASE 103;fixpower:=256;fixpow:=3
  726.                                     CASE 104;fixpower:=1024;fixpow:=4
  727.                                     CASE 105;fixpower:=2048;fixpow:=5
  728.                                     CASE 106;fixpower:=4096;fixpow:=6
  729.                                     CASE 107;fixpower:=8192;fixpow:=7
  730.                                     CASE 108;fixpower:=16384;fixpow:=8
  731.                                     CASE 109;fixpower:=32769;fixpow:=9
  732.                                     ENDSELECT
  733.                                 ENDIF
  734.                                 IF hit=76 THEN IF check THEN hand:=0
  735.                                 IF hit=78 THEN IF check THEN hand:=TRUE
  736.                                 IF hit=79 THEN IF check THEN hand:=3
  737.                                 IF hit=77
  738.                                     bound:=IF check THEN TRUE ELSE FALSE
  739.                                 ENDIF
  740.                                 IF hit=89 THEN waittof:=IF check THEN TRUE ELSE FALSE
  741.                                 IF ((hit>=80) AND (hit<=84))
  742.                                     rtdrag:=hit-80
  743.                                 ENDIF
  744.                                 IF hit=66 THEN quit:=TRUE
  745.                                 IF hit=4
  746.                                     updatecolors()
  747.                                     updatelist()
  748.                                 ENDIF
  749.                                 IF hit=3 THEN hitflag:=3
  750.                                 IF hit=2 THEN hitflag:=2
  751.                                 IF hit=1 THEN newproj:=TRUE
  752.                                 IF ((hit>=30) AND (hit<=39))
  753.                                     IF current_set<>(hit-30)
  754.                                         current_set:=hit-30
  755.                                         SetWindowPointerA(win,[$80000098,TRUE,WA_POINTERDELAY,TRUE,NIL,NIL])
  756.                                         FOR i:=0 TO MAX_CELL-1
  757.                                             cache_cell(i,CACHE_CHECK)
  758.                                         ENDFOR
  759.                                         docheck(20+current_palet,FALSE)
  760.                                         current_palet:=pb[current_set]
  761.                                         docheck(20+current_palet,TRUE)
  762.                                         updatecolors()
  763.                                         updatelist()
  764.                                     ENDIF
  765.                                 ENDIF
  766.                                 IF ((hit>=20) AND (hit<=29))
  767.                                     current_palet:=hit-20
  768.                                     updatecolors()
  769.                                 ENDIF
  770.                                 code:=iadd.nextselect
  771.                             ELSE
  772.                                 code:=MENUNULL
  773.                             ENDIF
  774.                         ENDWHILE
  775.                         updatecolors()
  776.                     ENDIF
  777.                     IF (mes.class=IDCMP_INTUITICKS) THEN drawx,drawy:=boundize(mes.mousex,mes.mousey)
  778.                     IF (mes.class=IDCMP_MOUSEMOVE) THEN drawx,drawy:=boundize(mes.mousex,mes.mousey)
  779.                     IF (mes.class=IDCMP_MOUSEBUTTONS)
  780.                         pauseflag:=FALSE
  781.                         IF mes.code=SELECTDOWN
  782.                             menuverify:=FALSE
  783.                             curobj,offx,offy:=findobj(mes.mousex,mes.mousey)
  784.                             origx:=mes.mousex-offx;origy:=mes.mousey-offy
  785.                             IF (curobj>-1)
  786.                                 dragmode:=TRUE;reportmousemoves(win)
  787.                                 removeobj(curobj)
  788.                                 createsaveback(curobj)
  789.                                 oldx:=-5000;oldy:=-5000
  790.                                 ii:=0
  791.                                 FOR i:=0 TO MAX_CELL-1
  792.                                     IF cell[i].mark=curobj THEN ii:=ii+1
  793.                                 ENDFOR
  794. StringF(string,'Object #\d has \d cells. @(\d[3],\d[3]) CHIP:\d',curobj,ii,mes.mousex-offx,mes.mousey-offy,AvailMem(MEMF_CHIP))
  795. SetWindowTitles(win,-1,string)
  796.                             ENDIF
  797.                         ENDIF
  798.                         IF mes.code=SELECTUP
  799.                             IF ((curobj>-1) AND (dragmode=TRUE))
  800.                                 IF backrast THEN ClipBlit(backrast,0,0,rp,oldx-offx,oldy-offy,iconwidth,iconheight,$C0)
  801.                                 placeobj(curobj,mes.mousex-offx,mes.mousey-offy);pauseflag:=TRUE
  802.                                 disposesaveback()
  803.                                 dragmode:=FALSE;curobj:=-1;noreportmousemoves(win)
  804.                                 SetWindowTitles(win,-1,' Play KiSS 0.88')
  805.                             ENDIF
  806.                         ENDIF
  807.                         IF mes.code=MENUDOWN
  808.                             IF (dragmode=TRUE)
  809.                                 IF backrast THEN ClipBlit(backrast,0,0,rp,oldx-offx,oldy-offy,iconwidth,iconheight,$C0)
  810.                                 placeobj(curobj,origx,origy);pauseflag:=TRUE
  811.                                 disposesaveback()
  812.                                 dragmode:=FALSE;curobj:=-1;noreportmousemoves(win)
  813.                                 SetWindowTitles(win,-1,' Play KiSS 0.88')
  814.                             ENDIF
  815.                         ENDIF
  816.                     ENDIF
  817.               Gt_ReplyIMsg(mes)
  818.                 ENDWHILE
  819.                 SELECT hitflag
  820.                 CASE 2
  821.                     WbenchToFront()
  822.                     splitname(filename,dir,file)
  823.                     ii:=AslRequest(filereq,[ASL_HAIL,'Select .CNF file',
  824.                             ASL_OKTEXT,'_Save',ASL_FILE,file,ASL_DIR,dir,
  825.                             ASLFR_DOPATTERNS,TRUE,ASLFR_DOSAVEMODE,TRUE,FILF_NEWIDCMP,TRUE,NIL,NIL])
  826.                     WbenchToBack()
  827.                     IF ii
  828.                         StrCopy(string,filename,ALL)
  829.                         StrCopy(filename,filereq.drawer,ALL)
  830.                         AddPart(filename,filereq.file,490)
  831.                         oldfh:=Open(filename,MODE_OLDFILE)
  832.                         newfh:=1
  833.                         IF oldfh
  834.                             Close(oldfh)
  835.                             menucolors(buffer)
  836.                             newfh:=EasyRequestArgs(win,[20,0,'Confirm overwrite!',
  837.                                 'File exists.\nDo you wish to overwrite?',
  838.                                 'Overwrite|Cancel'],0,0)
  839.                             updatecolors()
  840.                         ENDIF
  841.                         IF newfh
  842.                             SetWindowPointerA(win,[$80000098,TRUE,WA_POINTERDELAY,TRUE,NIL,NIL])
  843.                             filelen:=FileLength(string)
  844.                             IF (filelen>0)
  845.                                 filebuf:=New(filelen)
  846.                                 oldfh:=Open(string,MODE_OLDFILE)
  847.                                 IF oldfh
  848.                                     Read(oldfh,filebuf,filelen)
  849.                                     Close(oldfh)
  850.                                     bufptr:=filebuf
  851.                                     WHILE ((((Char(bufptr)<>10) OR (Char(bufptr)<>13)) AND (Char(bufptr+1)<>"$")) AND (bufptr<=(filebuf+filelen)))
  852.                                         bufptr:=bufptr+1
  853.                                     ENDWHILE
  854.                                     newfh:=Open(filename,MODE_NEWFILE)
  855.                                     IF newfh
  856.                                         Write(newfh,filebuf,(bufptr-filebuf+1))
  857.                                         FOR i:=0 TO 9
  858.                                             StringF(string,'\n$\d[1]',pb[i]);Write(newfh,string,StrLen(string))
  859.                                             ii:=0
  860.                                             FOR t:=0 TO MAX_CELL-1
  861.                                                 IF (cell[t].set[i]<10)
  862.                                                     ii:=bigger(ii,cell[t].mark)
  863.                                                 ENDIF
  864.                                             ENDFOR
  865.                                             FOR t:=0 TO ii STEP 16
  866.                                                 FOR tt:=t TO smaller(t+15,ii)
  867.                                                     zz:=-11
  868.                                                     FOR zzz:=0 TO MAX_CELL-1
  869.                                                         IF (cell[zzz].set[i]<10)
  870.                                                             IF (cell[zzz].mark=tt)
  871.                                                                 zz:=zzz
  872.                                                             ENDIF
  873.                                                         ENDIF
  874.                                                     ENDFOR
  875.                                                     IF zz>=0
  876.                                                         StringF(string,' \d,\d',cell[zz].x[i],cell[zz].y[i])
  877.                                                         Write(newfh,string,StrLen(string))
  878.                                                     ELSE
  879.                                                         Write(newfh,' *',2)
  880.                                                     ENDIF
  881.                                                 ENDFOR
  882.                                                 Write(newfh,'\n',1)
  883.                                             ENDFOR
  884.                                             Write(newfh,'\n',1)
  885.                                         ENDFOR
  886.                                         Write(newfh,'\n;save file written by - Play KiSS v0.88 for Amiga computers\n\n\n',61)
  887.                                         Close(newfh)
  888.                                     ENDIF
  889.                                 ENDIF
  890.                                 Dispose(filebuf)
  891.                             ENDIF
  892.                             ClearPointer(win)
  893.                         ENDIF
  894.                     ENDIF
  895.                 CASE 3
  896.                     menucolors(buffer)
  897.                     EasyRequestArgs(win,[20,0,'About "Play KiSS"',
  898.                             'Play KiSS v0.88 - November 21, 1994\nwritten by Chad Randall\n(crandall@garnet.msen.com)\n---\nKISS/GS4 compatibility:\n256 colors\n256 cells\nUnlimited screen size\n(All limits affected by CHIP memory)\n---\n\nReleased as\nPUBLIC DOMAIN',
  899.                             'Ok'],0,0)
  900.                     updatecolors()
  901.                 ENDSELECT
  902.  
  903.                 IF ((dragmode=TRUE) AND (curobj>=0))
  904.                     IF ((oldx<>drawx) OR (oldy<>drawy))
  905.                         IF (oldx<>-5000) THEN IF (backrast<>0) THEN ClipBlit(backrast,0,0,rp,oldx-offx,oldy-offy,iconwidth,iconheight,$C0)
  906.                         IF (backrast<>0) THEN ClipBlit(rp,drawx-offx,drawy-offy,backrast,0,0,iconwidth,iconheight,$C0)
  907.                         IF (rtdrag>=DRAG_DIRTY)
  908.                             IF ((maskbmap<>0) AND (iconbmap<>0))
  909.                                 BltBitMap(iconbmap,0,0,maskbmap,0,0,iconwidth,iconheight,1,1,0)
  910.                                 FOR i:=MAX_CELL-1 TO 0 STEP -1
  911.                                     IF (cell[i].set[current_set]<10)
  912.                                         IF (cell[i].clip_pix<>0)
  913.                                             IF (cell[i].mark=curobj)
  914.                                                 BltBitMap(cell[i].clip_pix,0,0,maskbmap,cell[i].xoffset,cell[i].yoffset,cell[i].xsize,cell[i].ysize,$E0,%00000001,0)
  915.                                             ELSE
  916.                                                 IF (((cell[i].x[current_set]+cell[i].xoffset)<(drawx-offx+iconwidth)) AND ((cell[i].x[current_set]+cell[i].xsize+cell[i].xoffset)>(drawx-offx)))
  917.                                                     IF (((cell[i].y[current_set]+cell[i].yoffset)<(drawy-offy+iconheight)) AND ((cell[i].y[current_set]+cell[i].ysize+cell[i].yoffset)>(drawy-offy)))
  918.                                                         zox:=0;zoy:=0
  919.                                                         zx:=(drawx-offx)-(cell[i].x[current_set]+cell[i].xoffset)
  920.                                                         zy:=(drawy-offy)-(cell[i].y[current_set]+cell[i].yoffset)
  921.                                                         IF (zx<=0)
  922.                                                             zox:=0
  923.                                                             zx:=Abs(zx)
  924.                                                         ELSE
  925.                                                             zox:=zx
  926.                                                             zx:=0
  927.                                                         ENDIF
  928.                                                         IF (zy<=0)
  929.                                                             zoy:=0
  930.                                                             zy:=Abs(zy)
  931.                                                         ELSE
  932.                                                             zoy:=zy
  933.                                                             zy:=0
  934.                                                         ENDIF
  935.                                                         zw:=limit(cell[i].xsize-zox,0,iconwidth-zx)
  936.                                                         zh:=limit(cell[i].ysize-zoy,0,iconheight-zy)
  937. ->    WriteF('\nBltBitMap($\h,\d,\d,$\h,\d,\d->\d,\d)',cell[i].clip_pix,zox,zoy,maskbmap,zx,zy,zw,zh)
  938.                                                         BltBitMap(cell[i].clip_pix,zox,zoy,maskbmap,zx,zy,zw,zh,$20,%00000001,0)
  939.                                                     ENDIF
  940.                                                 ENDIF
  941.                                             ENDIF
  942.                                         ENDIF
  943.                                     ENDIF
  944.                                 ENDFOR
  945.                                 IF ((rtdrag=DRAG_DIRTY) OR ((rtdrag=DRAG_SMART) AND (copybmap=0)))
  946.                                     BltMaskBitMapRastPort(iconbmap,0,0,rp,drawx-offx,drawy-offy,iconwidth,iconheight,%11100000,Long(maskbmap+8))
  947.                                 ELSE
  948.                                     IF ((copyrast<>0) AND (copybmap<>0))
  949.                                         BltBitMap(iconbmap,0,0,copybmap,0,0,iconwidth,iconheight,$C0,$FF,0)
  950.                                         BltBitMap(maskbmap,0,0,copybmap,0,0,iconwidth,iconheight,$80,$FF,0)
  951.                                         BltBitMapRastPort(maskbmap,0,0,rp,drawx-offx,drawy-offy,iconwidth,iconheight,$20)
  952.                                         BltBitMapRastPort(copybmap,0,0,rp,drawx-offx,drawy-offy,iconwidth,iconheight,$E0)
  953.                                     ENDIF
  954.                                 ENDIF
  955.                             ENDIF
  956.                         ENDIF
  957.                         IF ((rtdrag=DRAG_TOP) OR (rtdrag=DRAG_PAUSE))
  958.                             IF (maskbmap<>0) THEN BltBitMapRastPort(maskbmap,0,0,rp,drawx-offx,drawy-offy,iconwidth,iconheight,$20)
  959.                             IF (iconbmap<>0) THEN BltBitMapRastPort(iconbmap,0,0,rp,drawx-offx,drawy-offy,iconwidth,iconheight,$E0)
  960.                         ENDIF
  961.  
  962.                         IF waittof
  963.                             WaitBlit()
  964. ->                            FOR i:=0 TO 2
  965.                                 WaitTOF()
  966.                                 WaitBOVP(vp)
  967. ->                            ENDFOR
  968.                         ENDIF
  969.                         oldx:=drawx;oldy:=drawy;pauseflag:=FALSE
  970.                     ELSE
  971.                         IF pauseflag=FALSE
  972.                             IF (rtdrag=DRAG_PAUSE)
  973.                                 drawobj(curobj,drawx-offx,drawy-offy)
  974.                                 pauseflag:=TRUE
  975.                             ENDIF
  976.                         ENDIF
  977.                     ENDIF
  978.                 ENDIF
  979.             ENDWHILE
  980.             disposesaveback()
  981.             flushproj()
  982. ->            IF blankbmap THEN FreeBitMap(blankbmap);blankbmap:=0
  983.             closescreen()
  984.         ENDIF
  985.     ENDWHILE    
  986.  
  987. EXCEPT DO
  988.     FOR i:=0 TO MAX_CELL-1
  989.         DisposeLink(cell[i].name)
  990.     ENDFOR
  991.     IF hand1 THEN DisposeObject(hand1)
  992.     IF hand2 THEN DisposeObject(hand2)
  993.     flushproj()
  994.     END cell[MAX_CELL]
  995.     END palet[16]
  996.     END rectangle
  997. ->    IF blankbmap THEN FreeBitMap(blankbmap);blankbmap:=0
  998.     closescreen()
  999.     Dispose(buffer)
  1000.     Dispose(region1)
  1001.     IF ((exception="^C") AND (outputmode=0)) THEN WriteF('***BREAK\n')
  1002.     IF ((exception="Kick"))
  1003.         WriteF('You need at least OS 3.0 (Kickstart 39) to "Play KiSS"!!!\n')
  1004.         DisplayBeep(0)
  1005.     ENDIF
  1006.     IF filereq THEN FreeAslRequest(filereq)
  1007.     IF gadtoolsbase THEN CloseLibrary(gadtoolsbase)
  1008.     IF layersbase THEN CloseLibrary(layersbase)
  1009.     IF aslbase THEN CloseLibrary(aslbase)
  1010.     IF iconbase THEN CloseLibrary(iconbase)
  1011. ENDPROC
  1012.  
  1013. PROC unpackmenunumber(code)
  1014.     DEF menu,item,sub,c
  1015.     c:=code
  1016.     menu:=c AND %11111
  1017.     c:=Shr(c,5)
  1018.     item:=c AND %111111
  1019.     c:=Shr(c,6)
  1020.     sub:=c AND %11111
  1021. ENDPROC menu,item,sub
  1022.  
  1023. PROC packmenunumber(menu=MENUNULL,item=NOITEM,sub=NOSUB)
  1024.     DEF work
  1025.     IF menu=-1 THEN menu:=MENUNULL
  1026.     IF item=-1 THEN item:=NOITEM
  1027.     IF sub=-1 THEN sub:=NOSUB
  1028.     menu:=menu AND %11111
  1029.   item:=item AND %111111
  1030.   sub:=sub AND %11111
  1031.     work:=Shl(sub,8)
  1032.     work:=Shl(work,3)
  1033.     work:=(work OR (Shl(item,5)))
  1034.     work:=(work OR menu)
  1035. ENDPROC work
  1036.  
  1037. PROC findmenuitem(menu:PTR TO menu,title,item=NOITEM,subitem=NOSUB)
  1038.     DEF menuitem:PTR TO menuitem
  1039.     DEF localscratch
  1040.     IF title>0
  1041.         FOR localscratch:=1 TO title
  1042.             menu:=menu.nextmenu
  1043.         ENDFOR
  1044.     ENDIF
  1045.     menuitem:=menu
  1046.     IF item<>NOITEM
  1047.         menuitem:=menu.firstitem
  1048.         FOR localscratch:=1 TO item
  1049.             menuitem:=menuitem.nextitem
  1050.         ENDFOR
  1051.         IF (subitem<>NOSUB)
  1052.             menuitem:=menuitem.subitem
  1053.             IF subitem>0
  1054.                 FOR localscratch:=1 TO subitem
  1055.                     menuitem:=menuitem.nextitem
  1056.                 ENDFOR
  1057.             ENDIF
  1058.         ENDIF
  1059.     ENDIF
  1060. ENDPROC menuitem
  1061.  
  1062. PROC docheck(item,f=0)
  1063.     DEF mi:PTR TO menuitem,t,i,si
  1064.     t,i,si:=findmenuid(menu,item)  ->  Finds t,s,si using our USERID!
  1065.     mi:=findmenuitem(menu,t,i,si)  ->  Finds a menuitem struct using t,s,si!  Redundant...
  1066.     IF mi>50
  1067.         IF f=0
  1068.             IF (mi.flags AND CHECKED) THEN mi.flags:=(mi.flags-CHECKED)
  1069.         ELSE
  1070.             mi.flags:=(mi.flags OR CHECKED)
  1071.         ENDIF    
  1072.     ENDIF
  1073. ENDPROC
  1074.  
  1075. PROC findmenuid(menu:PTR TO menu,id)
  1076.     DEF menuitem:PTR TO menuitem,subitem:PTR TO menuitem
  1077.     DEF t=-1,i=-1,si=-1
  1078.     WHILE menu>0
  1079.         t:=t+1
  1080.         menuitem:=menu.firstitem
  1081.         WHILE menuitem>0
  1082.             i:=i+1
  1083.             subitem:=menuitem.subitem
  1084.             IF (Long(menuitem+34)=id) THEN RETURN t,i,-1
  1085.             WHILE subitem>0
  1086.                 si:=si+1
  1087.                 IF (Long(subitem+34)=id) THEN RETURN t,i,si
  1088.                 subitem:=subitem.nextitem            
  1089.             ENDWHILE
  1090.             menuitem:=menuitem.nextitem
  1091.             si:=-1
  1092.         ENDWHILE
  1093.         i:=-1
  1094.         menu:=menu.nextmenu
  1095.     ENDWHILE
  1096. ENDPROC -1,-1,-1
  1097.  
  1098. PROC boundize(dx,dy)
  1099.     IF bound
  1100.         dx:=limit(dx,offx,config_size_x-iconwidth+offx)
  1101.         dy:=limit(dy,offy,config_size_y-iconheight+offy-scr.barheight-1)
  1102.     ENDIF
  1103. ENDPROC dx,dy
  1104.  
  1105. PROC hex2int(str)
  1106.     DEF r=0
  1107.     WHILE (Char(str)<>0)
  1108.         IF ((Char(str)>="0") AND (Char(str)<="9"))
  1109.             r:=Shl(r,4)
  1110.             r:=r+(Char(str)-"0")
  1111.         ENDIF
  1112.         IF ((Char(str)>="A") AND (Char(str)<="F"))
  1113.             r:=Shl(r,4)
  1114.             r:=r+((Char(str)-"A")+10)
  1115.         ENDIF
  1116.         str:=str+1
  1117.     ENDWHILE
  1118. ENDPROC r
  1119.  
  1120. PROC menucolors(buffer)
  1121.     DEF i
  1122.     FOR i:=0 TO 3
  1123.         SetRGB32(vp,i,Long(buffer+(i*12)),Long(buffer+(i*12)+4),Long(buffer+(i*12)+8))
  1124.     ENDFOR
  1125.     FOR i:=17 TO 19
  1126.         SetRGB32(vp,i,Long(buffer+(i*12)),Long(buffer+(i*12)+4),Long(buffer+(i*12)+8))
  1127.     ENDFOR
  1128.     FOR i:=(Shl(1,retdepth(mode))-4) TO (Shl(1,retdepth(mode))-1)
  1129.         SetRGB32(vp,i,Long(buffer+(i*12)),Long(buffer+(i*12)+4),Long(buffer+(i*12)+8))
  1130.     ENDFOR
  1131. ENDPROC
  1132.  
  1133. PROC placeobj(obj,x,y,flag=FALSE)
  1134.     DEF i,w=0,h=0
  1135.     IF flag THEN removeobj(obj)
  1136.     IF bound
  1137.         FOR i:=0 TO MAX_CELL-1
  1138.             IF (cell[i].mark=obj)
  1139.                 w:=bigger(w,cell[i].xoffset+cell[i].xsize)
  1140.                 h:=bigger(h,cell[i].yoffset+cell[i].ysize)
  1141.             ENDIF
  1142.         ENDFOR
  1143.         x:=limit(x,0,config_size_x-w)
  1144.         y:=limit(y,0,config_size_y-h-scr.barheight-1)
  1145.     ENDIF
  1146.     FOR i:=0 TO MAX_CELL-1
  1147.         IF (cell[i].mark=obj)
  1148.             cell[i].x[current_set]:=x
  1149.             cell[i].y[current_set]:=y
  1150.         ENDIF
  1151.     ENDFOR
  1152.     drawobj(obj)
  1153. ENDPROC
  1154.  
  1155. PROC findobj(x,y)
  1156.     DEF i
  1157.     FOR i:=0 TO MAX_CELL-1
  1158.         IF ((cell[i].fix<=fixpower) OR (fixxed=TRUE))
  1159.         IF (cell[i].set[current_set]<10)
  1160.         IF (x>=(cell[i].xoffset+cell[i].x[current_set]))
  1161.             IF (y>=(cell[i].yoffset+cell[i].y[current_set]))
  1162.                 IF (x<(cell[i].xoffset+cell[i].x[current_set]+cell[i].xsize))
  1163.                     IF (y<(cell[i].yoffset+cell[i].y[current_set]+cell[i].ysize))
  1164.                         IF ReadPixel(cell[i].pix_rp,(x-(cell[i].xoffset+cell[i].x[current_set])),y-(cell[i].yoffset+cell[i].y[current_set]))>0
  1165.                             RETURN cell[i].mark,(x-cell[i].x[current_set]),(y-cell[i].y[current_set])
  1166.                         ENDIF
  1167.                     ENDIF
  1168.                 ENDIF
  1169.             ENDIF
  1170.         ENDIF
  1171.         ENDIF
  1172.         ENDIF
  1173.     ENDFOR
  1174. ENDPROC -1,-1,-1
  1175.  
  1176.  
  1177. PROC updatecolors()
  1178.     DEF i,pn=0,t
  1179.     FOR i:=0 TO 15
  1180.         IF (palet[i].color[current_palet]<>0)
  1181.             FOR t:=0 TO smaller(palet[i].color_num,15)
  1182.                 SetRGB32(vp,pn,(Long(palet[i].color[current_palet]+(t*SIZEOF color))),(Long(palet[i].color[current_palet]+(t*SIZEOF color)+4)),(Long(palet[i].color[current_palet]+(t*SIZEOF color)+8)))
  1183.                 pn:=pn+1;IF pn=256 THEN pn:=255
  1184.             ENDFOR
  1185.             pn:=(pn+15)/16*16
  1186.         ENDIF
  1187.     ENDFOR
  1188. ENDPROC
  1189.  
  1190. /*PROC oldmaskobj(obj,x,y)
  1191.     DEF sp[8]:LIST,i,t,sd
  1192.  
  1193.     FOR i:=0 TO 7
  1194.         sp[i]:=Long(cell[obj].pix+8+(i*8))
  1195.     ENDFOR
  1196.     sd:=cell[obj].pix.depth
  1197.  
  1198.     cell[obj].pix.depth:=depth
  1199.     IF cell[obj].bit_per_pixel=4
  1200.         FOR i:=0 TO 3
  1201.             IF (cell[obj].palet_num AND Shl(1,i))
  1202.                 PutLong(cell[obj].pix+8+((i+4)*4),Long(cell[obj].clip_pix+8))
  1203.             ELSE
  1204.                 PutLong(cell[obj].pix+8+((i+4)*4),Long(blankbmap+8))
  1205.             ENDIF
  1206.         ENDFOR
  1207.     ENDIF
  1208.  
  1209.     BltMaskBitMapRastPort(cell[obj].pix,0,0,rp,x+cell[obj].xoffset,y+cell[obj].yoffset,(cell[obj].pix.bytesperrow)*8,cell[obj].ysize,
  1210.         %11100000,Long(cell[obj].clip_pix+8))
  1211.  
  1212.     cell[obj].pix.depth:=sd
  1213.     FOR i:=0 TO 7
  1214.         PutLong(cell[obj].pix+8+(i*8),sp[i])
  1215.     ENDFOR
  1216. ENDPROC
  1217. */
  1218. PROC maskobj(obj,x,y)
  1219.     DEF dummy
  1220.  
  1221.     IF cell[obj].pix=0 THEN RETURN
  1222.  
  1223.     IF (cell[obj].clip_pix_rp<>0) THEN ClipBlit(cell[obj].clip_pix_rp,0,0,rp,x+cell[obj].xoffset,y+cell[obj].yoffset,cell[obj].xsize,cell[obj].ysize,$20)
  1224.     IF (cell[obj].pix_rp<>0) THEN ClipBlit(cell[obj].pix_rp,0,0,rp,x+cell[obj].xoffset,y+cell[obj].yoffset,cell[obj].xsize,cell[obj].ysize,$E0)
  1225.     dummy:=cell[obj].palet_num
  1226.     SELECT dummy
  1227.         CASE 0 ;rp.mask:=%00000000
  1228.         CASE 1 ;rp.mask:=%00010000
  1229.         CASE 2 ;rp.mask:=%00100000
  1230.         CASE 3 ;rp.mask:=%00110000
  1231.         CASE 4 ;rp.mask:=%01000000
  1232.         CASE 5 ;rp.mask:=%01010000
  1233.         CASE 6 ;rp.mask:=%01100000
  1234.         CASE 7 ;rp.mask:=%01110000
  1235.         CASE 8 ;rp.mask:=%10000000
  1236.         CASE 9 ;rp.mask:=%10010000
  1237.         CASE 10;rp.mask:=%10100000
  1238.         CASE 11;rp.mask:=%10110000
  1239.         CASE 12;rp.mask:=%11000000
  1240.         CASE 13;rp.mask:=%11010000
  1241.         CASE 14;rp.mask:=%11100000
  1242.         CASE 15;rp.mask:=%11110000
  1243.     ENDSELECT
  1244.     dummy:=retdepth(mode)
  1245.     SELECT dummy
  1246.         CASE 4;rp.mask:=(rp.mask AND %00000000)
  1247.         CASE 5;rp.mask:=(rp.mask AND %00010000)
  1248.         CASE 6;rp.mask:=(rp.mask AND %00110000)
  1249.         CASE 7;rp.mask:=(rp.mask AND %01110000)
  1250.         CASE 8;rp.mask:=(rp.mask AND %11110000)
  1251.     ENDSELECT
  1252.     IF (cell[obj].clip_pix_rp<>0) THEN ClipBlit(cell[obj].clip_pix_rp,0,0,rp,x+cell[obj].xoffset,y+cell[obj].yoffset,cell[obj].xsize,cell[obj].ysize,$E0)
  1253.     rp.mask:=%11111111
  1254. ENDPROC
  1255.  
  1256. PROC updatelist()
  1257.     DEF i,t
  1258.     SetRast(rp,0)
  1259.  
  1260.     SetWindowPointerA(win,[$80000098,TRUE,WA_POINTERDELAY,TRUE,NIL,NIL])
  1261.     FOR i:=MAX_CELL-1 TO 0 STEP -1
  1262.         IF (cell[i].mark>=0)
  1263.             IF (cell[i].set[current_set]<10)
  1264.                 maskobj(i,cell[i].x[current_set],cell[i].y[current_set])
  1265.             ENDIF
  1266.         ENDIF            
  1267.     ENDFOR
  1268.     ClearPointer(win)
  1269. ENDPROC
  1270.  
  1271. PROC removeobj(obj)
  1272.     DEF i,t
  1273.     DEF minx=10000,miny=10000
  1274.     DEF region,oldregion=0,rectangle:PTR TO rectangle
  1275.  
  1276.     region:=NewRegion()
  1277.     NEW rectangle
  1278.     rectangle.minx:=10000
  1279.     rectangle.miny:=10000
  1280.  
  1281.     FOR i:=0 TO MAX_CELL-1
  1282.         IF cell[i].mark=obj
  1283.             rectangle.minx:=smaller(rectangle.minx,cell[i].x[current_set]+cell[i].xoffset)
  1284.             rectangle.miny:=smaller(rectangle.miny,cell[i].y[current_set]+cell[i].yoffset)
  1285.             rectangle.maxx:=bigger(rectangle.maxx,cell[i].x[current_set]+cell[i].xoffset+cell[i].xsize)
  1286.             rectangle.maxy:=bigger(rectangle.maxy,cell[i].y[current_set]+cell[i].yoffset+cell[i].ysize)
  1287.         ENDIF
  1288.     ENDFOR
  1289.     OrRectRegion(region,rectangle)
  1290.  
  1291.  
  1292.     oldregion:=InstallClipRegion(win.wlayer,region)
  1293.  
  1294.     SetRast(rp,0)
  1295.     FOR i:=MAX_CELL-1 TO 0 STEP -1
  1296.         IF ((cell[i].mark>=0) AND (cell[i].mark<>obj))
  1297.             IF (cell[i].set[current_set]<10)
  1298.  
  1299.                 maskobj(i,cell[i].x[current_set],cell[i].y[current_set])
  1300.  
  1301. /*                IF (cell[i].clip_pix_rp<>0) THEN ClipBlit(cell[i].clip_pix_rp,0,0,rp,cell[i].x[current_set]+cell[i].xoffset,cell[i].y[current_set]+cell[i].yoffset,cell[i].xsize,cell[i].ysize,$20)
  1302.                 IF (cell[i].pix_rp<>0) THEN ClipBlit(cell[i].pix_rp,0,0,rp,cell[i].x[current_set]+cell[i].xoffset,cell[i].y[current_set]+cell[i].yoffset,cell[i].xsize,cell[i].ysize,$E0)
  1303.                 dummy:=cell[i].palet_num
  1304.                 SELECT dummy
  1305.                     CASE 0 ;rp.mask:=%00000000
  1306.                     CASE 1 ;rp.mask:=%00010000
  1307.                     CASE 2 ;rp.mask:=%00100000
  1308.                     CASE 3 ;rp.mask:=%00110000
  1309.                     CASE 4 ;rp.mask:=%01000000
  1310.                     CASE 5 ;rp.mask:=%01010000
  1311.                     CASE 6 ;rp.mask:=%01100000
  1312.                     CASE 7 ;rp.mask:=%01110000
  1313.                     CASE 8 ;rp.mask:=%10000000
  1314.                     CASE 9 ;rp.mask:=%10010000
  1315.                     CASE 10;rp.mask:=%10100000
  1316.                     CASE 11;rp.mask:=%10110000
  1317.                     CASE 12;rp.mask:=%11000000
  1318.                     CASE 13;rp.mask:=%11010000
  1319.                     CASE 14;rp.mask:=%11100000
  1320.                     CASE 15;rp.mask:=%11110000
  1321.                 ENDSELECT
  1322.                 dummy:=retdepth(mode)
  1323.                 SELECT dummy
  1324.                     CASE 4;rp.mask:=(rp.mask AND %00000000)
  1325.                     CASE 5;rp.mask:=(rp.mask AND %00010000)
  1326.                     CASE 6;rp.mask:=(rp.mask AND %00110000)
  1327.                     CASE 7;rp.mask:=(rp.mask AND %01110000)
  1328.                     CASE 8;rp.mask:=(rp.mask AND %11110000)
  1329.                 ENDSELECT
  1330.                 IF (cell[i].clip_pix_rp<>0) THEN ClipBlit(cell[i].clip_pix_rp,0,0,rp,cell[i].x[current_set]+cell[i].xoffset,cell[i].y[current_set]+cell[i].yoffset,cell[i].xsize,cell[i].ysize,$E0)
  1331.                 rp.mask:=%11111111*/
  1332.             ENDIF
  1333.         ENDIF            
  1334.     ENDFOR
  1335.     InstallClipRegion(win.wlayer,oldregion)
  1336.     END rectangle
  1337.     IF region
  1338.         DisposeRegion(region)
  1339.     ENDIF
  1340. ENDPROC
  1341.  
  1342. PROC drawobj(obj,xxxx=-500,yyyy=-500)
  1343.     DEF i,t
  1344.     DEF minx=10000,miny=10000
  1345.     DEF region,oldregion=0,rectangle:PTR TO rectangle
  1346.     DEF xx,yy
  1347.  
  1348.     region:=NewRegion()
  1349.     NEW rectangle
  1350.  
  1351.     rectangle.minx:=10000
  1352.     rectangle.miny:=10000
  1353.  
  1354.     FOR i:=0 TO MAX_CELL-1
  1355.         IF cell[i].mark=obj
  1356.             xx:=IF (xxxx=-500) THEN cell[i].x[current_set] ELSE xxxx
  1357.             yy:=IF (yyyy=-500) THEN cell[i].y[current_set] ELSE yyyy
  1358.             rectangle.minx:=smaller(rectangle.minx,xx+cell[i].xoffset)
  1359.             rectangle.miny:=smaller(rectangle.miny,yy+cell[i].yoffset)
  1360.             rectangle.maxx:=bigger(rectangle.maxx,xx+cell[i].xoffset+cell[i].xsize)
  1361.             rectangle.maxy:=bigger(rectangle.maxy,yy+cell[i].yoffset+cell[i].ysize)
  1362.         ENDIF
  1363.     ENDFOR
  1364.     OrRectRegion(region,rectangle)
  1365.  
  1366.     oldregion:=InstallClipRegion(win.wlayer,region)
  1367.  
  1368.     FOR i:=MAX_CELL-1 TO 0 STEP -1
  1369.         IF ((cell[i].mark>=0))
  1370.             IF (cell[i].set[current_set]<10)
  1371.                 
  1372. xx:=cell[i].x[current_set]
  1373. yy:=cell[i].y[current_set]
  1374.  
  1375.                 IF (cell[i].mark=obj)
  1376.                     IF (xxxx>-500)
  1377.                         IF (yyyy>-500)
  1378.                             xx:=xxxx
  1379.                             yy:=yyyy
  1380.                         ENDIF
  1381.                     ENDIF
  1382.                 ENDIF
  1383.  
  1384.                 maskobj(i,xx,yy)
  1385.  
  1386. /*
  1387. ->                xx:=IF ((x<>-50000) AND (cell[i].mark=obj)) THEN y ELSE cell[i].x[current_set]
  1388. ->                yy:=IF ((y<>-50000) AND (cell[i].mark=obj)) THEN x ELSE cell[i].y[current_set]
  1389.                 IF (cell[i].clip_pix_rp<>0) THEN ClipBlit(cell[i].clip_pix_rp,0,0,rp,xx+cell[i].xoffset,yy+cell[i].yoffset,cell[i].xsize,cell[i].ysize,$20)
  1390.                 IF (cell[i].pix_rp<>0) THEN ClipBlit(cell[i].pix_rp,0,0,rp,xx+cell[i].xoffset,yy+cell[i].yoffset,cell[i].xsize,cell[i].ysize,$E0)
  1391.                 dummy:=cell[i].palet_num
  1392.                 SELECT dummy
  1393.                     CASE 0 ;rp.mask:=%00000000
  1394.                     CASE 1 ;rp.mask:=%00010000
  1395.                     CASE 2 ;rp.mask:=%00100000
  1396.                     CASE 3 ;rp.mask:=%00110000
  1397.                     CASE 4 ;rp.mask:=%01000000
  1398.                     CASE 5 ;rp.mask:=%01010000
  1399.                     CASE 6 ;rp.mask:=%01100000
  1400.                     CASE 7 ;rp.mask:=%01110000
  1401.                     CASE 8 ;rp.mask:=%10000000
  1402.                     CASE 9 ;rp.mask:=%10010000
  1403.                     CASE 10;rp.mask:=%10100000
  1404.                     CASE 11;rp.mask:=%10110000
  1405.                     CASE 12;rp.mask:=%11000000
  1406.                     CASE 13;rp.mask:=%11010000
  1407.                     CASE 14;rp.mask:=%11100000
  1408.                     CASE 15;rp.mask:=%11110000
  1409.                 ENDSELECT
  1410.                 dummy:=retdepth(mode)
  1411.                 SELECT dummy
  1412.                     CASE 4;rp.mask:=(rp.mask AND %00000000)
  1413.                     CASE 5;rp.mask:=(rp.mask AND %00010000)
  1414.                     CASE 6;rp.mask:=(rp.mask AND %00110000)
  1415.                     CASE 7;rp.mask:=(rp.mask AND %01110000)
  1416.                     CASE 8;rp.mask:=(rp.mask AND %11110000)
  1417.                 ENDSELECT
  1418.                 IF (cell[i].clip_pix_rp<>0) THEN ClipBlit(cell[i].clip_pix_rp,0,0,rp,xx+cell[i].xoffset,yy+cell[i].yoffset,cell[i].xsize,cell[i].ysize,$E0)
  1419.                 rp.mask:=%11111111
  1420. */
  1421.             ENDIF
  1422.         ENDIF            
  1423.     ENDFOR
  1424.     InstallClipRegion(win.wlayer,oldregion)
  1425.     END rectangle
  1426.     IF region
  1427.         DisposeRegion(region)
  1428.     ENDIF
  1429. ENDPROC
  1430.  
  1431. /*PROC scanstring(fh,flag=FALSE)
  1432.     DEF l=-1,res=1
  1433.     DEF buf,str
  1434.     buf:=[0,0]:LONG
  1435.     str:=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]:LONG
  1436.     PutLong(buf,0)
  1437.     WHILE ((res>0) AND ((Char(buf)<>32) AND (Char(buf)<>10) AND (Char(buf)<>13) AND (Char(buf)<>9) AND (Char(buf)<>":") AND (Char(buf)<>"*") AND (Char(buf)<>",")))
  1438.         res:=Read(fh,buf,1)
  1439.         l:=l+1
  1440.         IF l<120
  1441.             PutChar(str+l,Char(buf))
  1442.         ENDIF
  1443.     ENDWHILE
  1444.     PutChar(str+l+1,0)
  1445.     IF flag THEN PutChar(str+l,0)
  1446. ENDPROC str,l*/
  1447.  
  1448. PROC openproj(str) HANDLE
  1449.     DEF fh=0
  1450.     DEF fib:PTR TO fileinfoblock
  1451.     DEF i,buf,f
  1452.     DEF newbuf=0
  1453.     DEF num=0,set=-1
  1454.     DEF set_str[MAX_SET]:LIST
  1455.     DEF palset
  1456.     DEF wbscr
  1457.  
  1458.     NEW fib;newbuf:=New(2000);buf:=[0,0,0]
  1459.     FOR i:=0 TO MAX_SET-1
  1460.         set_str[i]:=String(4096)
  1461.     ENDFOR
  1462.  
  1463.     StrCopy(filename,str,ALL)
  1464.     
  1465.     IF (fh:=Open(filename,MODE_OLDFILE))
  1466.  
  1467.         current_set:=0
  1468.         WbenchToFront()
  1469.         wbscr:=LockPubScreen('Workbench')
  1470.         outwin:=OpenWindowTagList(0,[WA_INNERWIDTH,480,WA_INNERHEIGHT,1,
  1471.             WA_TOP,32,WA_LEFT,80,
  1472.             WA_AUTOADJUST,TRUE,
  1473.             WA_TITLE,' Play KiSS 0.88 - Broken Spork Technologies',
  1474.             WA_FLAGS,WFLG_DEPTHGADGET OR WFLG_DRAGBAR OR WFLG_NOCAREREFRESH,
  1475.             WA_CUSTOMSCREEN,wbscr,
  1476.             NIL,NIL])
  1477.         IF wbscr THEN UnlockPubScreen(0,wbscr)
  1478.  
  1479.         palset:=0
  1480.         Delay(30)
  1481.         WHILE (Fgets(fh,newbuf,1024))
  1482.             i:=Char(newbuf)
  1483.             SELECT i
  1484.             CASE "%";load_palet(newbuf+1,palset);
  1485.                 palset:=palset+1;mode:=mode+1
  1486. ->            CASE "["
  1487.             CASE "("
  1488.                 load_config_size(newbuf+1)
  1489.             CASE "#"
  1490.                 load_config_cell(num,newbuf+1);num:=num+1
  1491.             CASE "$"
  1492.                 set:=set+1
  1493.                 StrCopy(set_str[set],newbuf+1,ALL)
  1494.             CASE " "
  1495.                 IF set>=0 THEN StrAdd(set_str[set],newbuf+1,ALL)
  1496.             ENDSELECT
  1497.         ENDWHILE
  1498.         FOR i:=0 TO set STEP 1
  1499.             load_config_set(i,set_str[i])
  1500.         ENDFOR
  1501.     ELSE
  1502.         Raise("DOS")
  1503.     ENDIF
  1504. EXCEPT DO
  1505.     IF outwin THEN CloseWindow(outwin);outwin:=0
  1506.     IF fh THEN Close(fh);fh:=0
  1507.     IF newbuf THEN Dispose(newbuf)
  1508.     END fib
  1509.     FOR i:=0 TO MAX_SET-1
  1510.         DisposeLink(set_str[i])
  1511.     ENDFOR
  1512.     IF exception="^C" THEN ReThrow()
  1513.     IF exception THEN RETURN FALSE
  1514. ENDPROC TRUE
  1515.  
  1516. PROC isdigit(s);IF (((s>="0") AND (s<="9")) OR (s=".") OR (s="-")) THEN RETURN TRUE;ENDPROC FALSE
  1517. PROC isalpha(s);IF (((s>="a") AND (s<="z")) OR ((s>="A") AND (s<="Z"))) THEN RETURN TRUE;ENDPROC FALSE
  1518. PROC ispunc(s);IF ((s=".") OR (s="-") OR (s="_")) THEN RETURN TRUE;ENDPROC FALSE
  1519.  
  1520. PROC scanforvalue(str)
  1521.     DEF l=0,i,s[100]:STRING,ins,iii=0
  1522.     WHILE (isdigit(Char(str+l)));l:=l+1;ENDWHILE
  1523.     StrCopy(s,str,l)
  1524.     ins:=InStr(str,'.')
  1525.     IF ((ins>0) AND (ins<=l))
  1526.         StrToLong(s,{i})
  1527.         StrToLong(s+ins+1,{iii})
  1528.     ELSE
  1529.         StrToLong(s,{i})
  1530.     ENDIF
  1531. ENDPROC i,l,iii
  1532.  
  1533. PROC scanforstring(str)
  1534.     DEF l=0
  1535.     WHILE (isdigit(Char(str+l)) OR isalpha(Char(str+l)) OR ispunc(Char(str+l)));l:=l+1;ENDWHILE
  1536. ENDPROC l
  1537.  
  1538. PROC load_config_cell(num,str)
  1539.     DEF p,c,i,j,n,secval
  1540.     DEF buf,mark,len
  1541.     buf:=[0,0,0,0,0,0,0,0,0,0,0,0,0]
  1542.     p:=str
  1543.     check_str(p)
  1544.     mark,len,secval:=scanforvalue(p)
  1545.     cell[num].mark:=mark
  1546.     cell[num].fix:=secval
  1547.     p:=p+len+1
  1548.  
  1549.     WHILE ((Char(p)=" ") OR (Char(p)=9));p:=p+1;ENDWHILE
  1550.     len:=scanforstring(p)
  1551.     StrCopy(cell[num].name,p,len)
  1552.     p:=p+len
  1553.  
  1554.     load_data_cell(cell[num].name,num)
  1555.     IF outwin
  1556.         StringF(string,'MEM:\d[9] OBJ #:\d[3] CEL #\d[3] (\d[3]x\d[3]) "\s" ',AvailMem(MEMF_CHIP),cell[num].mark,num,cell[num].xsize,cell[num].ysize,cell[num].name)
  1557.         SetWindowTitles(outwin,string,-1)
  1558.     ENDIF
  1559.     WHILE (Char(p)<>0)
  1560.         IF Char(p)="*"
  1561.             mark,len:=scanforvalue(p+1)
  1562.             cell[num].palet_num:=mark
  1563.             p:=p+1+len
  1564.         ENDIF
  1565.         IF Char(p)=":"
  1566.             p:=p+1
  1567.             FOR i:=0 TO MAX_SET-1;cell[num].set[i]:=50;ENDFOR
  1568.             WHILE (TRUE=TRUE)
  1569.                 mark:=(Char(p)-"0")
  1570.                 IF ((0<=mark) AND (mark<MAX_SET))
  1571.                     cell[num].set[mark]:=1
  1572.                 ENDIF
  1573.                 p:=p+1
  1574.                 EXIT (Char(p)=0)
  1575.             ENDWHILE
  1576.             cache_cell(num,CACHE_CHECK)
  1577.             RETURN
  1578.         ENDIF
  1579.     p:=p+1;ENDWHILE
  1580.     FOR i:=0 TO MAX_SET-1
  1581.         cell[num].set[i]:=1
  1582.     ENDFOR
  1583. ENDPROC
  1584.  
  1585. PROC load_palet(fn,num)
  1586.     DEF fh
  1587.     DEF buf
  1588.     DEF p,c,r,g,b,len
  1589.     DEF dir[500]:STRING,oldfile[100]:STRING
  1590.     DEF byte_l,byte_h
  1591.  
  1592.     buf:=[0,0,0,0,0,0,0,0,0,0]
  1593.     check_str(fn)
  1594.     len:=scanforstring(fn)
  1595.     PutChar(fn+len,0)
  1596.     IF outwin
  1597.         StringF(string,'PALETTE #\d:\s ',num,fn)
  1598.         SetWindowTitles(outwin,string,-1)
  1599.     ENDIF
  1600.     splitname(filename,dir,oldfile)
  1601.     AddPart(dir,fn,490)
  1602.     fh:=Open(dir,MODE_OLDFILE)
  1603.     IF fh
  1604.         StrCopy(palet[num],dir,ALL)
  1605.         IF (check_kiss_header(fh)=1)
  1606.             Read(fh,buf,32)
  1607.             IF Char(buf+4)=FILE_MARK_PALET
  1608.                 palet[num].color_num:=Char(buf+ 9)*256+Char(buf+ 8)
  1609.                 palet[num].palet_num:=Char(buf+11)*256+Char(buf+10)
  1610.                 palet[num].bit_per_pixel:=Char(buf+5)
  1611.             ENDIF
  1612.         ELSE
  1613.             palet[num].color_num:=GS1_MAX_COLOR
  1614.             palet[num].palet_num:=MAX_PAL
  1615.             palet[num].bit_per_pixel:=12
  1616.         ENDIF
  1617.         p:=0;WHILE (p<palet[num].palet_num)
  1618.             palet[num].color[p]:=New(SIZEOF color*palet[num].color_num+50)
  1619.             c:=0;WHILE (c<palet[num].color_num)
  1620.                 IF palet[num].bit_per_pixel=12
  1621.                     Read(fh,buf,2)
  1622.                     byte_l:=Char(buf)
  1623.                     byte_h:=Char(buf+1)
  1624.                     r:=(Shr(byte_l,4) AND $F)*$1111
  1625.                     g:=(byte_h AND $F)*$1111
  1626.                     b:=(byte_l AND $F)*$1111
  1627.                     r:=(Shl(Shl(r,8),8) OR r)
  1628.                     g:=(Shl(Shl(g,8),8) OR g)
  1629.                     b:=(Shl(Shl(b,8),8) OR b)
  1630.                 ENDIF
  1631.                 IF palet[num].bit_per_pixel=24
  1632.                     Read(fh,buf,1);r:=Char(buf)
  1633.                     Read(fh,buf,1);g:=Char(buf)
  1634.                     Read(fh,buf,1);b:=Char(buf)
  1635.                     r:=(Shl(Shl(r,8),8) OR r)
  1636.                     g:=(Shl(Shl(g,8),8) OR g)
  1637.                     b:=(Shl(Shl(b,8),8) OR b)
  1638.                 ENDIF
  1639.                 PutLong(palet[num].color[p]+(12*c),r)
  1640.                 PutLong(palet[num].color[p]+(12*c)+4,g)
  1641.                 PutLong(palet[num].color[p]+(12*c)+8,b)
  1642.             c:=c+1;ENDWHILE
  1643.         p:=p+1;ENDWHILE
  1644.         Close(fh)
  1645.     ENDIF
  1646.     
  1647. ENDPROC
  1648.  
  1649. PROC load_config_size(str)
  1650.     DEF p,mark,len
  1651.     check_str(str)
  1652.     p:=str
  1653.     mark,len:=scanforvalue(p)
  1654.     config_size_x:=bigger(mark,config_size_x)
  1655.     p:=p+len+1
  1656.     mark,len:=scanforvalue(p)
  1657.     config_size_y:=bigger(mark+barh+1,config_size_y)
  1658.     IF outwin
  1659.         StringF(string,'Environment (\d,\d)',config_size_x,config_size_y)
  1660.         SetWindowTitles(outwin,string,-1)
  1661.     ENDIF
  1662. ENDPROC
  1663.  
  1664. PROC load_config_set(num,str)
  1665.     DEF n,p,mark,len,x,y,i
  1666.     check_str(str)
  1667.     p:=str
  1668.     mark,len:=scanforvalue(p)
  1669.     p:=p+len+1
  1670.  
  1671.     pb[num]:=mark
  1672.  
  1673.     IF outwin
  1674.         StringF(string,'SET #\d uses Palette #\d ',num,mark)
  1675.         SetWindowTitles(outwin,string,-1)
  1676.     ENDIF
  1677.  
  1678.     n:=0;WHILE(n<MAX_CELL)
  1679.         IF Char(p)<>"*"
  1680.             mark,len:=scanforvalue(p)
  1681.             p:=p+len+1
  1682.             x:=mark
  1683.             mark,len:=scanforvalue(p)
  1684.             p:=p+len+1
  1685.             y:=mark
  1686.             FOR i:=0 TO MAX_CELL-1
  1687.                 IF cell[i].mark=n
  1688.                     cell[i].x[num]:=x
  1689.                     cell[i].y[num]:=y
  1690.                 ENDIF
  1691.             ENDFOR
  1692.             WHILE ((Char(p)=32) OR (Char(p)=9));p:=p+1;ENDWHILE
  1693.         ELSE
  1694.             p:=p+1
  1695.             WHILE ((Char(p)=32) OR (Char(p)=9));p:=p+1;ENDWHILE
  1696.         ENDIF
  1697.     n:=n+1;ENDWHILE
  1698. ENDPROC
  1699.  
  1700. PROC planesclip(bm1,bm2,maxiw,maxih)
  1701.     DEF hap,hap2,sp1[8]:LIST
  1702.     IF ((bm1=0) OR (bm2=0)) THEN RETURN
  1703.     FOR hap:=0 TO 7
  1704.         sp1[hap]:=Long(bm1+8+(hap*4))
  1705.     ENDFOR
  1706.  
  1707.     FOR hap:=0 TO 7
  1708.         PutLong((bm1+8),sp1[hap])
  1709.         IF (((sp1[hap]>0)) AND ((hap+1)<=Char(bm1+5)))
  1710.             BltBitMap(bm1,0,0,bm2,0,0,maxiw,maxih,IF hap=0 THEN 192 ELSE 224,$1,0)
  1711.         ENDIF
  1712.     ENDFOR    
  1713.     FOR hap:=0 TO 7
  1714.         PutLong(bm1+8+(hap*4),sp1[hap])
  1715.     ENDFOR
  1716. ->    BltBitMap(bm2,0,0,bm2,0,0,maxiw,maxih,$50,$1,0)
  1717. ENDPROC
  1718.  
  1719. PROC flushproj()
  1720.     DEF i,t
  1721.     FOR i:=0 TO MAX_CELL-1
  1722.         IF ((cell[i].clip_pix<>0))
  1723.             PutChar(cell[i].clip_pix+5,1)
  1724.             FOR t:=1 TO 7;PutLong(cell[i].clip_pix+8+(t*4),0);ENDFOR
  1725.         ENDIF
  1726.         cache_cell(i,CACHE_NEED)
  1727.         IF cell[i].pix
  1728.             FreeBitMap(cell[i].pix)
  1729.             cell[i].pix:=0
  1730.         ENDIF
  1731.         IF cell[i].clip_pix
  1732.             FreeBitMap(cell[i].clip_pix)
  1733.             cell[i].clip_pix:=0
  1734.         ENDIF
  1735.         IF (cell[i].pix_rp)
  1736.             Dispose(cell[i].pix_rp)
  1737.             cell[i].pix_rp:=0
  1738.         ENDIF
  1739.         IF (cell[i].clip_pix_rp)
  1740.             Dispose(cell[i].clip_pix_rp)
  1741.             cell[i].clip_pix_rp:=0
  1742.         ENDIF
  1743.         cell[i].mark:=-2
  1744.         FOR t:=0 TO MAX_SET-1
  1745.             cell[i].x[t]:=0
  1746.             cell[i].y[t]:=0
  1747.             cell[i].set[t]:=50
  1748.         ENDFOR
  1749.         IF (cell[i].catch<>0)
  1750.             IF (cell[i].catchsize<>0)
  1751.                 FreeMem(cell[i].catch,cell[i].catchsize);cell[i].catch:=0
  1752.             ENDIF
  1753.         ENDIF
  1754.         cell[i].mark:=-66
  1755.         cell[i].fix:=0
  1756.         cell[i].xoffset:=0
  1757.         cell[i].yoffset:=0
  1758.         cell[i].xsize:=0
  1759.         cell[i].ysize:=0
  1760.         cell[i].cache:=0
  1761.     ENDFOR
  1762.     FOR i:=0 TO MAX_PAL-1
  1763.         FOR t:=0 TO MAX_SET-1
  1764.             IF palet[i].color[t]
  1765.                 Dispose(palet[i].color[t])
  1766.                 palet[i].color[t]:=0
  1767.             ENDIF
  1768.         ENDFOR
  1769.     ENDFOR
  1770.     FOR i:=0 TO MAX_SET-1
  1771.         pb[i]:=0
  1772.     ENDFOR
  1773. ENDPROC
  1774.  
  1775. PROC splitname(str1,str2,str3)
  1776.   DEF filestart,pathlen,stt[5]:STRING
  1777.     filestart:=FilePart(str1)
  1778.     pathlen:=filestart-str1
  1779.     IF pathlen
  1780.         StrCopy(str2,str1,pathlen)
  1781.         MidStr(stt,str2,StrLen(str2)-1,1)
  1782.         IF StrCmp(stt,'/',ALL)
  1783.             MidStr(str2,str2,0,StrLen(str2)-1)
  1784.         ENDIF        
  1785.         StrCopy(str3,filestart,ALL)
  1786.     ELSE
  1787.         StrCopy(str2,'',ALL)
  1788.         StrCopy(str3,str1,ALL)
  1789.     ENDIF
  1790. ENDPROC
  1791.  
  1792. PROC openscreen(d)
  1793.     DEF cflag,lflag1=CHECKIT,lflag2=CHECKIT,lflag3=CHECKIT,lflag4=CHECKIT,lflag5=CHECKIT,lflag=CHECKIT
  1794.     DEF hflag1=CHECKIT,hflag2=CHECKIT,hflag3=CHECKIT,bflag=CHECKIT
  1795.     depth:=d
  1796.     scr:=OpenScreenTagList(NIL,[SA_LIKEWORKBENCH,TRUE,
  1797.         SA_DEPTH,depth,
  1798.         SA_TITLE,'Play KiSS 0.88',
  1799.         SA_COLORMAPENTRIES,256,
  1800.         SA_FULLPALETTE,TRUE,
  1801.         SA_WIDTH,config_size_x,
  1802.         SA_HEIGHT,config_size_y,
  1803.         SA_INTERLEAVED,TRUE,
  1804.         SA_AUTOSCROLL,TRUE,
  1805.         SA_PENS,[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]:INT,
  1806.         IF (modeid>0) THEN SA_DISPLAYID ELSE $80000000,
  1807.             modeid,
  1808.         NIL,NIL])
  1809.     IF scr=0 THEN Raise("SCR")
  1810.     IF (vis:=GetVisualInfoA(scr,NIL))=0 THEN RETURN "VIS"
  1811.     win:=OpenWindowTagList(0,[WA_WIDTH,scr.width,WA_HEIGHT,scr.height-scr.barheight-1,
  1812.         WA_TOP,scr.barheight+1,WA_LEFT,0,
  1813.         WA_FLAGS,WFLG_ACTIVATE OR WFLG_SMART_REFRESH,
  1814.         WA_BORDERLESS,TRUE,
  1815.         WA_BACKDROP,TRUE,
  1816.         WA_CUSTOMSCREEN,scr,
  1817.         WA_NEWLOOKMENUS,TRUE,
  1818.         WA_IDCMP,IDCMP_MENUPICK OR IDCMP_MOUSEBUTTONS OR IDCMP_INTUITICKS OR IDCMP_MENUVERIFY OR IDCMP_MOUSEMOVE,
  1819.         NIL,NIL])
  1820.     IF win=0 THEN Raise("WIN")
  1821.     vp:=scr.viewport
  1822.     cm:=vp.colormap
  1823.     rp:=win.rport
  1824.  
  1825.     cflag:=CHECKIT
  1826.     IF (fixxed=0) THEN cflag:=cflag OR CHECKED
  1827.     IF (hand=TRUE)     THEN hflag2:=hflag2 OR CHECKED
  1828.     IF (hand=0)         THEN hflag1:=hflag1 OR CHECKED
  1829.     IF (hand=3)         THEN hflag3:=hflag3 OR CHECKED
  1830.     IF (waittof) THEN lflag:=lflag OR CHECKED
  1831.     IF (bound) THEN bflag:=bflag OR CHECKED
  1832.     SELECT rtdrag
  1833.     CASE DRAG_TOP;         lflag1:=lflag1 OR CHECKED
  1834.     CASE DRAG_PAUSE;    lflag2:=lflag2 OR CHECKED
  1835.     CASE DRAG_DIRTY;    lflag3:=lflag3 OR CHECKED
  1836.     CASE DRAG_BUFFER;    lflag4:=lflag4 OR CHECKED
  1837.     CASE DRAG_SMART;    lflag5:=lflag5 OR CHECKED
  1838.     ENDSELECT
  1839.   IF (menu:=CreateMenusA([NM_TITLE,0,'Project','P',0,0,0,
  1840.                                                     NM_ITEM,0,'Redraw Screen','R',0,0,4,
  1841.                                                     NM_ITEM,0,'Open','O',0,0,1,
  1842.                                                     NM_ITEM,0,NM_BARLABEL,0,0,0,0,
  1843.                                                     NM_ITEM,0,'Save As...','S',0,0,2,
  1844.                                                     NM_ITEM,0,NM_BARLABEL,0,0,0,0,
  1845.                                                     NM_ITEM,0,'About','?',0,0,3,
  1846.                                                     NM_ITEM,0,'Quit','Q',0,0,66,
  1847.  
  1848.                                                     NM_TITLE,0,'Item',0,0,0,0,
  1849.                                                     NM_ITEM,0,'Sets',0,0,0,0,
  1850.                                                     NM_SUB,0,'Set 0','A',CHECKIT OR CHECKED,%1111111110,30,
  1851.                                                     NM_SUB,0,'Set 1','B',CHECKIT,%1111111101,31,
  1852.                                                     NM_SUB,0,'Set 2','C',CHECKIT,%1111111011,32,
  1853.                                                     NM_SUB,0,'Set 3','D',CHECKIT,%1111110111,33,
  1854.                                                     NM_SUB,0,'Set 4','E',CHECKIT,%1111101111,34,
  1855.                                                     NM_SUB,0,'Set 5','F',CHECKIT,%1111011111,35,
  1856.                                                     NM_SUB,0,'Set 6','G',CHECKIT,%1110111111,36,
  1857.                                                     NM_SUB,0,'Set 7','H',CHECKIT,%1101111111,37,
  1858.                                                     NM_SUB,0,'Set 8','I',CHECKIT,%1011111111,38,
  1859.                                                     NM_SUB,0,'Set 9','J',CHECKIT,%0111111111,39,
  1860.  
  1861.                                                     NM_ITEM,0,'Palettes',0,0,0,0,
  1862.                                                     NM_SUB,0,'Palette 0','0',CHECKIT OR CHECKED,%1111111110,20,
  1863.                                                     NM_SUB,0,'Palette 1','1',CHECKIT,%1111111101,21,
  1864.                                                     NM_SUB,0,'Palette 2','2',CHECKIT,%1111111011,22,
  1865.                                                     NM_SUB,0,'Palette 3','3',CHECKIT,%1111110111,23,
  1866.                                                     NM_SUB,0,'Palette 4','4',CHECKIT,%1111101111,24,
  1867.                                                     NM_SUB,0,'Palette 5','5',CHECKIT,%1111011111,25,
  1868.                                                     NM_SUB,0,'Palette 6','6',CHECKIT,%1110111111,26,
  1869.                                                     NM_SUB,0,'Palette 7','7',CHECKIT,%1101111111,27,
  1870.                                                     NM_SUB,0,'Palette 8','8',CHECKIT,%1011111111,28,
  1871.                                                     NM_SUB,0,'Palette 9','9',CHECKIT,%0111111111,29,
  1872.  
  1873.                                                     NM_TITLE,0,'Settings',0,0,0,0,
  1874.                                                     NM_ITEM,0,'Screen Boundaries?',0,bflag,0,77,
  1875.  
  1876.                                                     NM_ITEM,0,'Drag Strength',0,0,0,0,
  1877.                                                     NM_SUB,0,'0',0,CHECKIT,%1111111110,100,
  1878.                                                     NM_SUB,0,'1',0,                CHECKIT,%1111111101,101,
  1879.                                                     NM_SUB,0,'2',0,                CHECKIT,%1111111011,102,
  1880.                                                     NM_SUB,0,'3',0,                CHECKIT,%1111110111,103,
  1881.                                                     NM_SUB,0,'4',0,                CHECKIT,%1111101111,104,
  1882.                                                     NM_SUB,0,'5',0,                CHECKIT,%1111011111,105,
  1883.                                                     NM_SUB,0,'6',0,                CHECKIT,%1110111111,106,
  1884.                                                     NM_SUB,0,'7',0,                CHECKIT,%1101111111,107,
  1885.                                                     NM_SUB,0,'8',0,                CHECKIT,%1011111111,108,
  1886.                                                     NM_SUB,0,'9',0,                CHECKIT,%0111111111,109,
  1887.  
  1888.                                                     NM_ITEM,0,'Pointer',0,0,0,0,
  1889.                                                     NM_SUB,0,'Normal',0,hflag1,    %110,76,
  1890.                                                     NM_SUB,0,'Hand',0,hflag2,        %101,78,
  1891.                                                     NM_SUB,0,'Blank',0,hflag3,    %011,79,
  1892.  
  1893.                                                     NM_ITEM,0,'Drag Type',0,0,0,0,
  1894.                                                     NM_SUB,0,'Always on top',                        0,lflag1,%11110,80,
  1895.                                                     NM_SUB,0,'Layered, on pause',                0,lflag2,%11101,81,
  1896.                                                     NM_SUB,0,'Layered, quick&dirty',        0,lflag3,%11011,82,
  1897.                                                     NM_SUB,0,'Layered, buffered',                0,lflag4,%10111,83,
  1898.                                                     NM_SUB,0,'Layered, smart buffered',    0,lflag5,%01111,84,
  1899.                                                     NM_SUB,0,NM_BARLABEL,0,0,0,0,
  1900.                                                     NM_SUB,0,'Wait for blitter?',0,lflag,0,89,
  1901.  
  1902.                                                     NM_END,0,'End','x',0,0,0]:newmenu,NIL))=NIL THEN Raise("MENU")
  1903.     LayoutMenusA(menu,vis,[GTMN_NEWLOOKMENUS,TRUE,NIL,NIL])
  1904.     SetMenuStrip(win,menu)
  1905. ENDPROC
  1906.  
  1907. PROC closescreen()
  1908.     IF win
  1909.         CloseWindow(win)
  1910.         win:=0
  1911.     ENDIF
  1912.     IF menu
  1913.         FreeMenus(menu)
  1914.         menu:=0
  1915.     ENDIF
  1916.     IF vis
  1917.         FreeVisualInfo(vis)
  1918.         vis:=0
  1919.     ENDIF
  1920.     IF scr
  1921.         CloseScreen(scr)
  1922.         scr:=0
  1923.     ENDIF
  1924.  
  1925. ENDPROC
  1926.  
  1927. PROC retdepth(m)
  1928.     SELECT m
  1929.     CASE 0;RETURN 4
  1930.     CASE 1;RETURN 4
  1931.     CASE 2;RETURN 5
  1932.     CASE 3;RETURN 6
  1933.     CASE 4;RETURN 6
  1934.     CASE 5;RETURN 7
  1935.     CASE 6;RETURN 7
  1936.     CASE 7;RETURN 7
  1937.     CASE 8;RETURN 7
  1938.     ENDSELECT
  1939. ENDPROC 8
  1940.  
  1941. PROC smaller(val1,val2);IF val1<val2;RETURN val1;ELSE;RETURN val2;ENDIF;ENDPROC
  1942. PROC bigger(val1,val2);IF val1>val2;RETURN val1;ELSE;RETURN val2;ENDIF;ENDPROC
  1943. PROC limit(val1,val2,val3);IF val1<val2 THEN RETURN val2
  1944.             IF val1>val3 THEN RETURN val3;ENDPROC val1
  1945.  
  1946.  
  1947. hand1bm:
  1948.     INT    2,22
  1949.     CHAR    0,2
  1950.     INT    0
  1951.     LONG    0,0,0,0,0,0,0,0
  1952.  
  1953. hand2bm:
  1954.     INT    2,22
  1955.     CHAR    0,2
  1956.     INT    0
  1957.     LONG    0,0,0,0,0,0,0,0
  1958.  
  1959. hand3bm:
  1960.     INT    2,1
  1961.     CHAR    0,2
  1962.     INT    0
  1963.     LONG    0,0,0,0,0,0,0,0
  1964.  
  1965.  
  1966. hand1dataa:
  1967.     LONG    $03000380,$03800380,$038003e0,$03f00368,$c37ae3ef,$73fb3fff
  1968.     LONG    $1fff0fff,$0fff07ff,$07fe03fe,$03f803f8,$01f80000
  1969. hand1datab:
  1970.     LONG    $00000080,$00800080,$00800080,$00900090,$00840011,$00050001
  1971.     LONG    $00010001,$00010003,$0002000e,$00080008,$01f80000
  1972.  
  1973. hand2dataa:
  1974.     LONG    $00000000,$00000300,$038003e0,$03f00b68,$1f7a1bef,$1ffb1fff
  1975.     LONG    $1fff0fff,$0fff07ff,$07fe03fe,$03f803f8,$01f80000
  1976. hand2datab:
  1977.     LONG    $00000000,$00000000,$00800080,$04900490,$00840411,$00050001
  1978.     LONG    $00010001,$00010003,$0002000e,$00080008,$01f80000
  1979.  
  1980. hand3dataa:
  1981.     LONG %10000000000000000000000000000000
  1982.     LONG %00000000000000000000000000000000
  1983. hand3datab:
  1984.     LONG %10000000000000000000000000000000
  1985.     LONG %00000000000000000000000000000000
  1986.